微信小程序?qū)崿F(xiàn)手指拖動(dòng)選項(xiàng)排序
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)手指拖動(dòng)選項(xiàng)排序的具體代碼,供大家參考,具體內(nèi)容如下
效果:

wxml:
<view>
<view class="dileititle">手指移動(dòng)選項(xiàng)排序</view>
<view style="width:740rpx;height:80vh;overflow-y:auto;padding:0 90rpx;margin:auto;" id="movebox">
<block wx:for="{{list}}" wx:key="index">
<view catchtouchmove="listitemmove" catchtouchend="listitemmove" data-index="{{index}}" class="flex1 dileiitemlist" id="movelist{{index}}" style="left:0;right:0;{{nowmoveindex==index?('position:absolute;top:'+movetop+'px;height:'+itemheight+'px;'):''}}">
<view class="{{moveoutindex==index?'changemovenow':''}}" style="height:0;transition: height 0.2s;"></view>
<view class="ranknum">{{index+1}}</view>
<view class="flex1" style="border-radius:10rpx;width:440rpx;position:relative;color:#fff;">
<view style="flex:1;text-align: center;margin-right: 20rpx;padding: 20rpx 20rpx;background:#8eb1f7;border-radius:10rpx;">{{item.member.nickname}}</view>
</view>
</view>
</block>
</view>
</view>
<button class='tijiao' catchtap="lastsubmit">確定</button>
js:
let app = getApp()
app.unitgameinfo = {"members":[{"member":{"nickname":"小程序照片合成","job":"ckext"},},{"member":{"nickname":"高球丸子"},},{"member":{"nickname":"DRobertdsf","job":"黃金"},},{"member":{"nickname":"erer","job":"ckext"},},{"member":{"nickname":"just do it","job":"黃金"},},{"member":{"nickname":"888"},}],};
Page({
data: {
},
onLoad: function (options) {
var info = app.unitgameinfo,list;
list = info.members;
this.setData({options,info,list});
this.getwxmlcode("#movebox",(resp)=>{
this.setData({movebox:resp})
setTimeout(()=>{this.getwxmlcode("#movelist0",(res)=>{
this.setData({movelist0:res})
var jiange = res.top-resp.top;
var yiban = res.bottom - res.top + jiange;
this.setData({
itemheight:res.bottom - res.top,
jiange:yiban, //兩條中間到另一條的距離
jianqu:resp.top-(res.bottom - res.top)/2, //位置要減去距離
})
})},300)
})
},
getwxmlcode(str,cal){
const query1 = wx.createSelectorQuery()
query1.select(str).boundingClientRect()
query1.selectViewport().scrollOffset()
query1.exec((res) => {
if(cal) cal(res[0])
})
},
listitemmove(e){
// console.log(e)
if(e.type=="touchmove"){
var movetop = e.touches[0].pageY-this.data.itemheight;
var moveoutindex = parseInt((movetop-this.data.jianqu)/this.data.jiange);
if(e.currentTarget.dataset.index<=moveoutindex) moveoutindex++;
this.moveoutindex = moveoutindex;
this.setData({nowmoveindex:e.currentTarget.dataset.index,movetop,moveoutindex})
}else{
let index = e.currentTarget.dataset.index,score = this.data.list;
let data = {...score[index]};
score.splice(index,1);
if(index<=this.moveoutindex-1) this.moveoutindex--;
score.splice(this.moveoutindex,0,data);
this.setData({list:score,moveoutindex:-1,nowmoveindex:-1});
}
},
onShow: function(){
},
lastsubmit(){
console.log(this.data.list)
},
})
wxss:
page{background-color: #fff;font-size:30rpx;text-align: center;color: #2952a5;}
.tijiao{
color: #fff;font-size: 30rpx;line-height: 2.8;
margin: 20rpx auto 20rpx;width:80vw;position: fixed;bottom: 50rpx;left: 10vw;
background-color: #2952a5;border-radius:50rpx;
}
.dileiitemlist{justify-content: center;padding-top:30rpx;flex-wrap: wrap;}
.dileititle{font-size: 32rpx;line-height: 100rpx;}
.ranknum{width:60rpx;height: 60rpx;line-height: 60rpx;text-align: center;border-radius:50%;border:1rpx solid #2952a5;margin-right:30rpx;}
.changemovenow{width:100%;height:60px!important;}
.flex1{display:flex;align-items:center;}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript 錯(cuò)誤處理與調(diào)試經(jīng)驗(yàn)總結(jié)
在Web開發(fā)過程中,編寫JavaScript程序時(shí)或多或少會(huì)遇到各種各樣的錯(cuò)誤,有語法錯(cuò)誤,邏輯錯(cuò)誤。如果是一小段代碼,可以通過仔細(xì)檢查來排除錯(cuò)誤,但如果程序稍微復(fù)雜點(diǎn),調(diào)試JS便成為一個(gè)令Web開發(fā)者很頭痛的問題。2010-08-08
bootstrap自定義樣式之bootstrap實(shí)現(xiàn)側(cè)邊導(dǎo)航欄功能
bootstrap自帶的響應(yīng)式導(dǎo)航欄是向下滑動(dòng)的,有時(shí)滿足不了個(gè)性化的需求,需要做一個(gè)類似于android drawerLayout 側(cè)滑的菜單,這就是我要實(shí)現(xiàn)的bootstrap自定義側(cè)滑菜單。接下來通過本文給大家介紹bootstrap實(shí)現(xiàn)側(cè)邊導(dǎo)航欄功能,感興趣的朋友一起看看吧2018-09-09
avascript中的自執(zhí)行匿名函數(shù)應(yīng)用示例
javascript中的自執(zhí)行匿名函數(shù)可以用它創(chuàng)建命名空間,只要把自己所有的代碼都寫在這個(gè)特殊的函數(shù)包裝內(nèi),那么外部就不能訪問,除非你允許2014-09-09
js動(dòng)態(tài)調(diào)用css屬性的小規(guī)律及實(shí)例說明
本篇文章主要介紹了js動(dòng)態(tài)調(diào)用css屬性的小規(guī)律及實(shí)例說明。需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12
用html+css+js實(shí)現(xiàn)的一個(gè)簡單的圖片切換特效
這篇文章主要介紹了用html+css+js實(shí)現(xiàn)的一個(gè)簡單的圖片切換特效,需要的朋友可以參考下2014-05-05
給localStorage設(shè)置一個(gè)過期時(shí)間的方法分享
我們都知道localStorage不主動(dòng)刪除,永遠(yuǎn)不會(huì)銷毀,那么如何設(shè)置localStorage的過期時(shí)間呢?下面這篇文章主要給大家介紹了關(guān)于如何給localStorage設(shè)置一個(gè)過期時(shí)間的相關(guān)資料,需要的朋友可以參考下2018-11-11

