最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

工作中遇到一個(gè)上傳圖片長(zhǎng)按后拖動(dòng)排序的一個(gè)功能,于是寫下了一個(gè)小demo。希望能對(duì)你有遇到的問(wèn)題有幫助。

演示效果:

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({

? /**
? ?* 頁(yè)面的初始數(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)聽(tīng)頁(yè)面加載
? ?*/
? 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)聽(tīng)頁(yè)面初次渲染完成
? ?*/
? onReady: function () {
??
? },

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

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

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

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

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

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


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

? },
? //觸摸開(kāi)始
? 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;
? ? ? ? //向后移動(dòng)
? ? ? ? if (beginIndex < endIndex) {
? ? ? ? ? let tem = data[beginIndex];
? ? ? ? ? for (let i = beginIndex; i < endIndex; i++) {
? ? ? ? ? ? data[i] = data[i + 1]
? ? ? ? ? }
? ? ? ? ? data[endIndex] = tem;
? ? ? ? }
? ? ? ? //向前移動(dòng)
? ? ? ? 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
? ? })
? },
? //滑動(dòng)
? 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;
}

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

相關(guān)文章

  • js實(shí)現(xiàn)圖片加載淡入淡出效果

    js實(shí)現(xiàn)圖片加載淡入淡出效果

    這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)圖片加載淡入淡出效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • 5個(gè)你不知道的JavaScript字符串處理庫(kù)(小結(jié))

    5個(gè)你不知道的JavaScript字符串處理庫(kù)(小結(jié))

    這篇文章主要介紹了5個(gè)你不知道的JavaScript字符串處理庫(kù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • 微信小程序自定義帶價(jià)格顯示日歷效果

    微信小程序自定義帶價(jià)格顯示日歷效果

    這篇文章主要為大家詳細(xì)介紹了微信小程序自定義帶價(jià)格顯示日歷效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • 獲取表單控件原始(初始)值的方法

    獲取表單控件原始(初始)值的方法

    獲取表單控件原始值在某些時(shí)候還是比較實(shí)用的,具體的獲取方法如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助
    2013-08-08
  • 詳解JavaScript中的作用域

    詳解JavaScript中的作用域

    作用域是JavaScript中一個(gè)重要的概念,它決定了變量和函數(shù)在代碼中的可訪問(wèn)性和可見(jiàn)性,了解JavaScript的作用域?qū)τ诰帉懜咝А⒖删S護(hù)的代碼至關(guān)重要,本文將深入介紹JavaScript作用域相關(guān)的知識(shí)點(diǎn),其中包括作用域類型,作用域鏈,變量提升以及閉包等
    2023-08-08
  • JavaScript深入淺出__proto__和prototype

    JavaScript深入淺出__proto__和prototype

    這篇文章主要介紹了JavaScript深入淺出__proto__和prototype,文章基于JavaScript的相關(guān)資料展開(kāi)詳細(xì)的內(nèi)容介紹。具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • 移動(dòng)前端圖片壓縮上傳的實(shí)例

    移動(dòng)前端圖片壓縮上傳的實(shí)例

    下面小編就為大家分享一篇移動(dòng)前端圖片壓縮上傳的實(shí)例。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起小編過(guò)來(lái)看看吧
    2017-12-12
  • 詳解Javascript中DOM的范圍

    詳解Javascript中DOM的范圍

    “DOM2級(jí)遍歷和范圍”模塊定義了“范圍”接口。通過(guò)范圍可以選擇文檔中的一個(gè)區(qū)域,而不必考慮節(jié)點(diǎn)的界限(選擇在后臺(tái)完成,對(duì)用戶是不可見(jiàn)的)。下面這篇文章主要介紹了Javascript中DOM范圍的相關(guān)資料,需要的朋友可以參考下。
    2017-02-02
  • javascript實(shí)現(xiàn)日期時(shí)間動(dòng)態(tài)顯示示例代碼

    javascript實(shí)現(xiàn)日期時(shí)間動(dòng)態(tài)顯示示例代碼

    這篇文章主要介紹了javascript實(shí)現(xiàn)日期時(shí)間動(dòng)態(tài)顯示示例代碼,頁(yè)面動(dòng)態(tài)顯示時(shí)間變化的方法有很多,本文為大家介紹下使用javascript的具體實(shí)現(xiàn),感興趣的朋友可以參考一下
    2015-09-09
  • Google 靜態(tài)地圖API實(shí)現(xiàn)代碼

    Google 靜態(tài)地圖API實(shí)現(xiàn)代碼

    Google 靜態(tài)地圖 文檔說(shuō)的很詳細(xì),這里就不在啰嗦了!
    2010-11-11

最新評(píng)論

都江堰市| 砚山县| 同德县| 丹东市| 从化市| 昭苏县| 鄯善县| 社旗县| 抚松县| 丘北县| 斗六市| 福贡县| 大关县| 鹿邑县| 永善县| 逊克县| 庆城县| 赫章县| 哈巴河县| 平谷区| 凌海市| 文化| 九台市| 长垣县| 二手房| 什邡市| 漯河市| 长武县| 沅陵县| 丹凤县| 海林市| 英山县| 缙云县| 广平县| 阜宁县| 大同县| 个旧市| 康马县| 定州市| 特克斯县| 德令哈市|