wxml页面编写

<view class="container">
  <view bindtap="box" class="box" >
    <view disable-scroll="true" wx:for="{{content}}" bindtouchmove="move" bindtouchstart="movestart" bindtouchend="moveend" data-index="{{item.id}}" data-main="{{mainx}}" class="main {{mainx == item.id? 'mainmove':'mainend'}}" style="left:{{start.x}}px; top:{{start.y}}px">{{item.content}}</view>
  </view>
</view>

  

wxss部分

.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
/* padding: 200rpx 0; */
box-sizing: border-box;
} .box {
width: 100%;
position: relative
} .main {
width: 94%;
height: 124rpx;
background: #FFF;
margin: 20rpx auto;
text-align: center;
/* line-height: 124rpx; */
position: relative;
} .mainmove {
position: absolute;
opacity: 0.7
} .maind {
background: #fff;
border: 1px dashed #efefef;
} .mainend {
position: static;
opacity: 1;
display: flex;
}
.containerBox{
width: 80%;
height: 124rpx;
position: absolute;
top: 0;
left: 0;
margin: 20rpx auto;
}
js部分

page上方添加
var x,y,x1,y1,x2,y2,index,currindex,n,yy;
var arr1 = [{ content:11,id:1 },{ content:22,id:2 },{ content:33,id:3 },{ content:44,id:4 },{ content:55,id:5 }] //这里初始化的时候替换自己要更改的数组
data中空数组变量
page(
  data:{
    mainx:0,
    content:[
{ content:11,id:1 },{ content:22,id:2 },{ content:33,id:3 },{ content:44,id:4 },{ content:55,id:5 }], //这里初始化的时候替换自己要更改的数组
    start:{x:0,y:0}
  }
)
moveend:function(){
if(y2 != 0){
var arr = [];
for(var i=0; i<this.data.content.length; i++){
arr.push(this.data.content[i]);
}
var nx = this.data.content.length;
n=1;
for(var k=2; k<nx; k++){
if(y2>(52*(k-1)+k*2-26)){
n=k;
}
}
if(y2>(52*(nx-1)+nx*2-26)){
n = nx;
}
arr.splice((currindex-1),1);
arr.splice((n-1),0,arr1[currindex-1]);
arr1 = [];
for(var m=0; m<this.data.content.length; m++){
arr[m].idType = m+1;
arr1.push(arr[m]);
}
// console.log(arr1);
this.setData({
mainx:"",
content:arr,
opacity:1
})
}
},
move:function(e){
yy = e.currentTarget.offsetTop;
x2 = e.touches[0].clientX-x+x1;
y2 = e.touches[0].clientY-y+y1;
this.setData({
mainx:currindex,
opacity:0.7,
start:{x:x2,y:y2}
})
},
movestart:function(e){
currindex = e.target.dataset.index;
x = e.touches[0].clientX;
y = e.touches[0].clientY;
x1 = e.currentTarget.offsetLeft;
y1 = e.currentTarget.offsetTop;
},

最新文章

  1. java web学习总结(二十五) -------------------JSP中的九个内置对象
  2. lintcode bugfree and good codestyle note
  3. Baraja演示15种不同的洗牌特效
  4. linux basis --- common commands
  5. NYOJ题目64鸡兔同笼
  6. HDU4971 A simple brute force problem.(强连通分量缩点 + 最大权闭合子图)
  7. 开年钜献:华清远见金牌讲师名家大讲堂(Android开发篇)
  8. Replace Nested Conditional with Guard Clauses(用卫语句代替嵌套循环)
  9. SVN的使用(转载)
  10. POJ_1065_Wooden_Sticks_(动态规划,LIS+鸽笼原理)
  11. .Net冷知识之动态查找类型时的程序集路径问题
  12. 间支付系统,DataGridView
  13. Microsoft Azure IoTHub Serials 1 - 使用Android设备与Azure IoTHub进行交互
  14. Jquery(一) 初识Jquery,简单使用Jquery。
  15. Django之ORM
  16. PHP和PHP-FPM 配置文件优化
  17. std::vector push_back报错Access violation
  18. 分布式任务调度系统xxl-job搭建
  19. 《Inside C#》笔记(十三) 多线程 下
  20. Android 性能优化 SparseArray【转载】

热门文章

  1. Cloud Computing Chapter3 (云计算第三章)
  2. 分页PHP
  3. Laravel-QueryList-采集
  4. Wireshark抓包工具解析HTTPS包
  5. Swagger整合Jwt授权配置
  6. AQS 源码解读之加锁篇
  7. 在kali中安装两个版本的python
  8. Redis常见延迟问题定位与分析
  9. Arcgis更新sde库许可
  10. 女朋友汇总表格弄了大半天,我实在看不下去了,用40行代码解决问题 | Python使用openpyxl库读写表格Excel(xlsx)