国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序?qū)崿F(xiàn)圖片拖拽切換位置

這篇具有很好參考價值的文章主要介紹了微信小程序?qū)崿F(xiàn)圖片拖拽切換位置。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、實現(xiàn)效果

微信小程序 view 換位置,微信小程序,javascript,前端

二、實現(xiàn)代碼

所用到組件
movable-area movable-view

HTML

<movable-area class="areaBlock">
    <view class="picList">
        <view class="picRelative" wx:for="{{picList}}" bind:longpress="showMoveBlock" bind:touchend="hideMoveBlock" data-index="{{index}}">
            // 占位圖
            <image class="dynamicImg" src="{{item.tempFilePath}}" mode="aspectFill" lazy-load="false" binderror="" bindload=""></image>
            <image class="deleteImg" wx:if="{{picList.length !== 0}}" catchtap="deleteImg" src="/images/function/deleteImg.png" mode="scaleToFill" lazy-load="false" binderror="" bindload="" data-index="{{index}}" />
            // 移動模塊
            <movable-view wx:if="{{!moveIng}}" class="areaMove" bindchange="bindchange" direction="all" damping="30" x="{{defaultX}}" y="{{defaultY}}" disabled="{{currentTouchIndex === index ? false : true}}" style="z-index: {{currentTouchIndex === index ? '3' : '1'}}">
                <image class="{{currentTouchIndex === index ? 'areaImg' : ''}}" bindtap="previewImg" data-index="{{index}}" src="{{item.tempFilePath}}" mode="aspectFill" lazy-load="false" binderror="" bindload="" />
            </movable-view>
        </view>
    </view>
</movable-area>

JS

  data: {
    currentTouchIndex: -1,
    currentX: 0,
    currentY: 0,
    defaultX: 0,
    defaultY: 0,
    moveIng: false
  },
  methods: {
    // 顯示底層可移動模塊
    showMoveBlock(e){
      const { index } = e.currentTarget.dataset
      this.setData({
        currentTouchIndex: index
      })
    },
    // 滑動結(jié)束(判斷滑塊當(dāng)前位置)
    hideMoveBlock(e){
      if(this.data.currentTouchIndex === -1){
        return
      }
      const { index } = e.currentTarget.dataset
      const boundary = 20
      // 判斷圖片移動位置
      const directionX = this.data.currentX < 0 ? 'left' : 'right'
      const directionY = this.data.currentY < 0 ? 'top' : 'bottom'
      const currentX = Math.abs(this.data.currentX)
      const currentY = Math.abs(this.data.currentY)
      // 判斷是否需要交換位置
      const needChangeFlag = (currentX % 96) - (Math.floor(currentX / 96) * 40) > boundary || (currentY % 96) - (Math.floor(currentY / 96) * 40) > boundary ? false : true
      if(!needChangeFlag || (currentX < 20 && currentY < 20)){
        this.setData({
          defaultX: 0,
          defaultY: 0
        })
      }else{
        this.setData({
          moveIng: true
        })
        const moveX = directionX === 'left' ? -Math.floor(currentX / 96) : Math.floor(currentX / 96)
        const moveY = directionY === 'top' ? -Math.floor(currentY / 96) : Math.floor(currentY / 96)
        let middleCount = 0
        let changeIndex = -1
        // 根據(jù)移動方向和個數(shù)獲取移動后的index(3為一行數(shù)量)
        if(Math.abs(moveY) > 1){
          middleCount = 3 * (Math.abs(moveY) - 1)
        }
        if(Math.abs(moveY) === 0){
          changeIndex = index + moveX
        }else{
          changeIndex = moveY < 0 ? index - (3 - moveX) - middleCount : index + (3 + moveX) + middleCount
        }
        this.exchangePosition(index,changeIndex)
      }
      setTimeout(()=>{
        this.setData({
          moveIng: false,
          currentTouchIndex: -1
        })
      },300)
    },
    // 圖片數(shù)組交換位置
    exchangePosition(initIndex,changeIndex){
      if(changeIndex > this.data.picList.length - 1){
        return
      }
      let initPicList = this.data.picList
      const before = this.data.picList[initIndex]
      const after = this.data.picList[changeIndex]
      initPicList[initIndex] = after
      initPicList[changeIndex] = before
      this.setData({
        picList: initPicList,
        defaultX: 0,
        defaultY: 0,
      })
    },
    // 獲取滑動移動的xy
    bindchange: throttle(function (e){
      this.setData({
        currentX: Math.floor(e.detail.x),
        currentY: Math.floor(e.detail.y)
      })
    },150),
    // 刪除圖片
    deleteImg(e){
      const indexs = e.currentTarget.dataset.index
      const picList = this.data.picList
      const picUrlList = this.data.picUrlList
      picList.splice(indexs,1)
      picUrlList.splice(indexs,1)
      this.setData({
        picList,
        picUrlList
      })
    },
    // 預(yù)覽圖片
    previewImg(e){
      const indexs = e.currentTarget.dataset.index
      let urlList = []
      this.data.picList.forEach((item)=>{
        urlList.push(item.tempFilePath)
      })
      wx.previewImage({
        current: this.data.picList[indexs].tempFilePath, // 當(dāng)前顯示圖片的 http 鏈接
        urls: urlList // 需要預(yù)覽的圖片 http 鏈接列表
      })
    },
  }

CSS

.areaBlock{
    width: 100%;
    height: 100%;
}
.picList{
    padding: 0 30rpx 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    position: relative;
}
.areaMove{
    position: absolute;
    left: 0;
    top: 0;
    width: 196rpx;
    height: 196rpx;
}
.areaMove image{
    width: 100%;
    height: 100%;
    border-radius: 10rpx;
}
.areaImg{
    box-shadow: 0 2rpx 18rpx 0 #7BC4FF;
}
.picRelative{
    position: relative;
    width: 196rpx;
    height: 196rpx;
    margin-right: 40rpx;
    margin-bottom: 40rpx;
    border: 1rpx dashed rgba(0, 0, 0, 0.06);
}
.picRelative:nth-child(3n){
    margin-right: 0;
}
.dynamicImg{
    width: 100%;
    height: 100%;
    border-radius: 10rpx;
}
.deleteImg{
    position: absolute;
    top: -20rpx;
    right: -20rpx;
    z-index: 2;
    width: 44rpx;
    height: 44rpx;
}

三、總結(jié)

圖片到達可交換位置的容錯值及圖片一行的數(shù)量可以因需求而異。

如果有邏輯錯誤或冗余代碼敬請指正。文章來源地址http://www.zghlxwxcb.cn/news/detail-524852.html

到了這里,關(guān)于微信小程序?qū)崿F(xiàn)圖片拖拽切換位置的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 微信小程序圖片拖拽排序組件

    微信小程序圖片拖拽排序組件

    圖片拖拽排序是一個比較常用的組件,常用于發(fā)帖或者評論等內(nèi)容上傳模塊,我借鑒了《一款優(yōu)雅的小程序拖拽排序組件實現(xiàn)》這篇文章的拖拽思路,封裝成wx-drag-img發(fā)布到npm 實現(xiàn)原理:每個圖片初始化我都會封裝成一個拖拽的數(shù)據(jù)結(jié)構(gòu),然后通過觸發(fā)touch事件,根據(jù)key的變

    2024年02月09日
    瀏覽(21)
  • 微信小程序scroll-view滑動的時候滑動到指定位置

    微信小程序scroll-view滑動的時候滑動到指定位置

    效果實現(xiàn) 1.滑動的時候調(diào)動滑動事件bindscroll=\\\"scroll\\\" scroll-with-animation 過渡動畫 scroll-top=\\\"{{scrolltop}}\\\" 距離頂部多少高度 2.在調(diào)用scroll里面的事件函數(shù) 這里使用的是獲取手機屏幕大小的寬度 res.screenWidth 來自適應(yīng)頭部懸浮的位置的顯示與隱藏 opacity:( 1 - e.detail.scrollTop / 100 / 3).to

    2024年02月16日
    瀏覽(19)
  • 微信小程序中的拖拽和縮放圖片功能

    在現(xiàn)代的移動應(yīng)用開發(fā)中,拖拽和縮放功能變得越來越重要。它們不僅使應(yīng)用程序更具交互性,還為用戶提供了更直觀、更高效的使用體驗。微信小程序作為一個流行的開發(fā)平臺,也提供了這樣的功能。以下是在微信小程序中實現(xiàn)拖拽和縮放圖片的步驟和注意事項。 1.設(shè)置圖

    2024年03月14日
    瀏覽(46)
  • 【微信小程序-原生開發(fā)】列表 - 拖拽排序(官方組件 movable-area 和 movable-view 的用法)

    【微信小程序-原生開發(fā)】列表 - 拖拽排序(官方組件 movable-area 和 movable-view 的用法)

    實現(xiàn)邏輯詳見代碼的注釋 需要根據(jù)各項的內(nèi)容,調(diào)整或動態(tài)生成 ITEM_HEIGHT 值 因 movable-view 是絕對定位,不方便實現(xiàn)水平居中,所以設(shè)定 width: 100%; 占滿寬度

    2024年02月11日
    瀏覽(23)
  • 微信小程序中,圖片的位置設(shè)置

    微信小程序中,圖片的位置設(shè)置

    在編寫小程序的時候,難免會涉及到圖片的位置放置。 以及具體的wxss格式的設(shè)置,在這里想進行一個具體格式的講解。 具體樣例如下圖:黃色熒光筆所繪: ?要實現(xiàn)該操作,根據(jù)圖易見,其是由圖片,以及文字構(gòu)成的。 1.放置一個大的view,包裹住整行 2.每個圖片與文字再放

    2024年01月18日
    瀏覽(11)
  • uniapp - 微信小程序?qū)崿F(xiàn)騰訊地圖位置標點展示,將指定地點進行標記選點并以一個圖片圖標展示出來(詳細示例源碼,一鍵復(fù)制開箱即用)

    在uniapp微信小程序平臺端開發(fā),簡單快速的實現(xiàn)在地圖上進行位置標點功能,使用騰訊地圖并進行標點創(chuàng)建和設(shè)置(可以自定義標記點的圖片)。 你只需要復(fù)制代碼,改個標記圖標和位置即可。

    2024年02月08日
    瀏覽(87)
  • 微信小程序?qū)崿F(xiàn)拖拽的小球

    ???????? 目錄 前言? js? 獲取微信小程序中獲取系統(tǒng)信息 觸摸移動事件的處理函數(shù) 觸摸結(jié)束事件的處理函數(shù) ?用于監(jiān)聽頁面滾動事件 全局參數(shù)? html CSS 小程序開發(fā)提供了豐富的API和事件處理函數(shù),使得開發(fā)者可以方便地實現(xiàn)各種交互功能。其中,拖拽功能是一個在許多

    2024年02月12日
    瀏覽(26)
  • 微信小程序 實現(xiàn)最簡單的組件拖拽

    微信小程序 實現(xiàn)最簡單的組件拖拽

    最近在自主學(xué)習(xí)微信小程序的開發(fā);對于零基礎(chǔ)入門(沒有學(xué)習(xí)過前端)的我,查閱了許多微信小程序拖拽的實現(xiàn),大部分要么實現(xiàn)起來太復(fù)雜了,要么封裝組件太復(fù)雜了,附帶了拖拽之后排序等功能;因此寫下這篇個人覺得最好理解的 微信小程序元素拖拽的實現(xiàn); 這邊采用了

    2024年02月09日
    瀏覽(20)
  • 微信小程序?qū)崿F(xiàn)支付寶支付——web-view實現(xiàn)

    微信小程序?qū)崿F(xiàn)支付寶支付——web-view實現(xiàn)

    由于使用到的微信小程序需要實現(xiàn)支付功能,而微信支付的申請手續(xù)較為繁瑣,所以使用了支付寶支付,但是微信小程序正常情況不支持支付寶支付,所以我使用了web-view內(nèi)嵌了支付寶的h5支付。 不會使用支付寶沙箱支付的同學(xué)可以看這篇文章Springboot支付寶沙箱支付 代碼如下

    2024年02月11日
    瀏覽(58)
  • 微信小程序人臉識別/采集改進版(wx.faceDetect)-支持人臉中心位置校驗,人臉圖片采集(速度更快),人臉搜索

    1. 初始化人臉識別 2. 創(chuàng)建 camera 上下文 CameraContext 對象 3.獲取 Camera 實時幀數(shù)據(jù) 4.人臉識別,使用前需要通過 wx.initFaceDetect 進行一次初始化,推薦使用相機接口返回的幀數(shù)據(jù) 5.校驗人臉是否居中(可調(diào)整或注釋) 6. 把滿足條件的當(dāng)前幀數(shù)據(jù)轉(zhuǎn)為base64(通過canvas轉(zhuǎn)換臨時文件在

    2024年02月09日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包