欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序?qū)崿F(xiàn)長按拖拽排序功能

 更新時間:2022年05月23日 17:17:36   作者:haicome  
這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)長按拖拽排序功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

工作中遇到一個上傳圖片長按后拖動排序的一個功能,于是寫下了一個小demo。希望能對你有遇到的問題有幫助。

演示效果:

wxml

<view class='outer' >
? <view class='inner'>
? ? <movable-area>
? ? ? <block wx:for="{{data}}">
? ? ? ? <view class='item' ?id="{{item.index}}" data-index='{{index}}' bindlongpress='_longtap' bindtouchstart='touchs' bindtouchend='touchend' bindtouchmove='touchm'>
? ? ? ? ? <text>{{item.index}}</text>
? ? ? ? </view>
? ? ? </block>
? ? ? <movable-view x="{{x}}" y="{{y}}" direction="all" damping="{{5000}}" friction="{{1}}" disabled="{{disabled}}">
? ? ? ? <view class='item-move' hidden='{{hidden}}'>
? ? ? ? </view>
? ? ? </movable-view>
? ? </movable-area>
? </view>
</view>

js

// test/test.js
Page({

? /**
? ?* 頁面的初始數(shù)據(jù)
? ?*/
? data: {
? ? hidden:true,
? ? flag:false,
? ? x:0,
? ? y:0,
? ? data:[{index:1},
? ? ? { index: 2 },
? ? ? { index: 3 },
? ? ? { index: 4 },
? ? ? { index: 5 },
? ? ? { index: 6 },
? ? ? { index: 7 },
? ? ],
? ? disabled: true,
? ? elements:[]
? },

? /**
? ?* 生命周期函數(shù)--監(jiān)聽頁面加載
? ?*/
? onLoad: function (options) {
? ??
? ? ? var query = wx.createSelectorQuery();
? ? ? var nodesRef = query.selectAll(".item");
? ? ? nodesRef.fields({
? ? ? dataset: true,
? ? ? rect:true
? ? ??
? ? },(result)=>{
? ? ? ? this.setData({
? ? ? ? ? elements: result
? ? ? ? })
? ? ? ? }).exec()
? },

? /**
? ?* 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
? ?*/
? onReady: function () {
??
? },

? /**
? ?* 生命周期函數(shù)--監(jiān)聽頁面顯示
? ?*/
? onShow: function () {
??
? },

? /**
? ?* 生命周期函數(shù)--監(jiān)聽頁面隱藏
? ?*/
? onHide: function () {
??
? },

? /**
? ?* 生命周期函數(shù)--監(jiān)聽頁面卸載
? ?*/
? onUnload: function () {
??
? },

? /**
? ?* 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動作
? ?*/
? onPullDownRefresh: function () {
??
? },

? /**
? ?* 頁面上拉觸底事件的處理函數(shù)
? ?*/
? onReachBottom: function () {
??
? },

? /**
? ?* 用戶點擊右上角分享
? ?*/
? onShareAppMessage: function () {
??
? },


? //長按
? _longtap:function(e){
? ? const detail = e.detail;
? ? this.setData({
? ? ? x: e.currentTarget.offsetLeft,
? ? ? y: e.currentTarget.offsetTop
? ? })
? ? this.setData({
? ? ? hidden: false,
? ? ? flag:true
? ? })

? },
? //觸摸開始
? touchs:function(e){
? ? this.setData({
? ? ? beginIndex:e.currentTarget.dataset.index
? ? })
? },
? //觸摸結(jié)束
? touchend:function(e){
? ? if (!this.data.flag) {
? ? ? return;
? ? }
? ? const x = e.changedTouches[0].pageX
? ? const y = e.changedTouches[0].pageY
? ? const list = this.data.elements;
? ? let data = this.data.data
? ? for(var j = 0; j<list.length; j++){
? ? ? const item = list[j];
? ? ? if(x>item.left && x<item.right && y>item.top && y<item.bottom){
? ? ? ? const endIndex = item.dataset.index;
? ? ? ? const beginIndex = this.data.beginIndex;
? ? ? ? //向后移動
? ? ? ? if (beginIndex < endIndex) {
? ? ? ? ? let tem = data[beginIndex];
? ? ? ? ? for (let i = beginIndex; i < endIndex; i++) {
? ? ? ? ? ? data[i] = data[i + 1]
? ? ? ? ? }
? ? ? ? ? data[endIndex] = tem;
? ? ? ? }
? ? ? ? //向前移動
? ? ? ? if (beginIndex > endIndex) {
? ? ? ? ? let tem = data[beginIndex];
? ? ? ? ? for (let i = beginIndex; i > endIndex; i--) {
? ? ? ? ? ? data[i] = data[i - 1]
? ? ? ? ? }
? ? ? ? ? data[endIndex] = tem;
? ? ? ? }

? ? ? ? this.setData({
? ? ? ? ? data: data
? ? ? ? })
? ? ? }
? ? }
? ? this.setData({
? ? ? hidden: true,
? ? ? flag: false
? ? })
? },
? //滑動
? touchm:function(e){
? ? if(this.data.flag){
? ? ? const x = e.touches[0].pageX
? ? ? const y = e.touches[0].pageY
? ? ? this.setData({
? ? ? ? x: x - 75,
? ? ? ? y: y - 45
? ? ? })
? ? }
? }
})

wxss

/* test/test.wxss */
.outer{
? width: 650rpx;
? height: 400rpx;
? border: 1px solid red;
? margin: 0 auto;
}
.inner{
? width: 100%;
? height: 100%;
}
movable-area{
? width: 100%;
? height: 100%;
}
.item{
? display: inline-block;
? width: 150rpx;
? height: 150rpx;
? border: 1px solid red;
? text-align: center;
? line-height: 150rpx;
}

.index-first{
? display: inline-block;
? width: 15rpx;
? height: 150rpx;
? background: firebrick;
}

.item-move{
? display: inline-block;
? width: 150rpx;
? height: 150rpx;
? border: 1px solid blue;
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 基于JavaScript 性能優(yōu)化技巧心得(分享)

    基于JavaScript 性能優(yōu)化技巧心得(分享)

    下面小編就為大家分享一篇基于JavaScript 性能優(yōu)化技巧心得,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • JS打開新窗口防止被瀏覽器阻止的方法

    JS打開新窗口防止被瀏覽器阻止的方法

    這篇文章主要介紹了JS打開新窗口防止被瀏覽器阻止的方法,分析對比了常用方法與改進方法,是非常實用的技巧,需要的朋友可以參考下
    2015-01-01
  • 微信小程序?qū)崿F(xiàn)五星評價

    微信小程序?qū)崿F(xiàn)五星評價

    這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)五星評價,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • JS實現(xiàn)隨機抽取三人

    JS實現(xiàn)隨機抽取三人

    這篇文章主要為大家詳細介紹了JS實現(xiàn)隨機抽取三人,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • JavaScript判斷頁面加載完之后再執(zhí)行預(yù)定函數(shù)的技巧

    JavaScript判斷頁面加載完之后再執(zhí)行預(yù)定函數(shù)的技巧

    這篇文章主要介紹了JavaScript判斷頁面加載完之后再執(zhí)行預(yù)定函數(shù)的技巧,原理還是利用監(jiān)聽器監(jiān)聽元素事件、被觸發(fā)則執(zhí)行函數(shù),需要的朋友可以參考下
    2016-05-05
  • 詳解JS實現(xiàn)系統(tǒng)登錄頁的登錄和驗證

    詳解JS實現(xiàn)系統(tǒng)登錄頁的登錄和驗證

    這篇文章主要介紹了JS實現(xiàn)系統(tǒng)登錄頁的登錄和驗證,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • JS運動特效之完美運動框架實例分析

    JS運動特效之完美運動框架實例分析

    這篇文章主要介紹了JS運動特效之完美運動框架,結(jié)合實例形式分析了javascript針對運動中的元素屬性檢測與判斷相關(guān)操作技巧,需要的朋友可以參考下
    2018-01-01
  • JavaScript Pinia代替 Vuex的可行性分析

    JavaScript Pinia代替 Vuex的可行性分析

    這篇文章主要介紹了JavaScript中Pinia是否可以代替Vuex,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • D3.js實現(xiàn)折線圖的方法詳解

    D3.js實現(xiàn)折線圖的方法詳解

    眾所周知圖表是數(shù)據(jù)圖形化的表示,通過形象的圖表來展示數(shù)據(jù),比如條形圖,折線圖,餅圖等等??梢暬瘓D表可以幫助開發(fā)者更容易理解復(fù)雜的數(shù)據(jù),提高生產(chǎn)的效率和 Web 應(yīng)用和項目的可靠性?,F(xiàn)在就讓我們大家一起來學(xué)習(xí)用D3.js來實現(xiàn)折線圖。
    2016-09-09
  • JS實現(xiàn)獲取當(dāng)前所在周的周六、周日示例分析

    JS實現(xiàn)獲取當(dāng)前所在周的周六、周日示例分析

    這篇文章主要介紹了JS實現(xiàn)獲取當(dāng)前所在周的周六、周日,結(jié)合具體實例形式分析了javascript針對日期時間的獲取與計算相關(guān)操作技巧,需要的朋友可以參考下
    2019-05-05

最新評論