使用微信小程序怎么实现一个运动步数排行功能

本篇文章给大家分享的是有关使用微信小程序怎么实现一个运动步数排行功能,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

林甸ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!

wxml



 
  
   
   
   {{item.rank}}
   
     {{item.name}}
   
  
     {{item.pace}}
    
   
   
   
   
   删除
  
 

wxss

/* pages/leftSwiperDel/index.wxss */
view{
  box-sizing: border-box;
}
.item-box{
  width: 700rpx;
  margin: 0 auto;
  padding:40rpx 0;
}
.items{
  width: 100%;
}
.item{
  position: relative;
  border-top: 2rpx solid #eee;
  height: 120rpx;
  line-height: 120rpx;
  overflow: hidden;
   
}


.item:last-child{
  border-bottom: 2rpx solid #eee;
}
.inner{
  position: absolute;
  top:0;
}
.inner.txt{
  background-color: #fff;
  width: 100%;
  z-index: 5;
  padding:0 10rpx;
  transition: left 0.2s ease-in-out;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.inner.del{
  background-color: #e64340;
  width: 180rpx;text-align: center;
  z-index: 4;
  right: 0;
  color: #fff
}
.item-icon{
  width: 64rpx;
  height: 64rpx;
  vertical-align: middle;
  margin-right: 16rpx;
  margin-left:13px;
  border-radius:50%;

}

.item-data{
 float: right;
 margin-right:5%;}

.rankpace{
 color: #fa7e04;
}

js

// pages/leftSwiperDel/index.js
Page({
 data: {
  delBtnWidth: 180//删除按钮宽度单位(rpx)
 },
 onLoad: function (options) {
  // 页面初始化 options为页面跳转所带来的参数
  this.initEleWidth();
  this.tempData();
 },
 onReady: function () {
  // 页面渲染完成
 },
 onShow: function () {
  // 页面显示
 },
 onHide: function () {
  // 页面隐藏
 },
 onUnload: function () {
  // 页面关闭
 },
 touchS: function (e) {
  if (e.touches.length == 1) {
   this.setData({
    //设置触摸起始点水平方向位置
    startX: e.touches[0].clientX
   });
  }
 },
 touchM: function (e) {
  if (e.touches.length == 1) {
   //手指移动时水平方向位置
   var moveX = e.touches[0].clientX;
   //手指起始点位置与移动期间的差值
   var disX = this.data.startX - moveX;
   var delBtnWidth = this.data.delBtnWidth;
   var txtStyle = "";
   if (disX == 0 || disX < 0) {//如果移动距离小于等于0,文本层位置不变
    txtStyle = "left:0px";
   } else if (disX > 0) {//移动距离大于0,文本层left值等于手指移动距离
    txtStyle = "left:-" + disX + "px";
    if (disX >= delBtnWidth) {
     //控制手指移动距离最大值为删除按钮的宽度
     txtStyle = "left:-" + delBtnWidth + "px";
    }
   }
   //获取手指触摸的是哪一项
   var index = e.target.dataset.index;
   var list = this.data.list;
   list[index].txtStyle = txtStyle;
   //更新列表的状态
   this.setData({
    list: list
   });
  }
 },
 touchE: function (e) {
  if (e.changedTouches.length == 1) {
   //手指移动结束后水平位置
   var endX = e.changedTouches[0].clientX;
   //触摸开始与结束,手指移动的距离
   var disX = this.data.startX - endX;
   var delBtnWidth = this.data.delBtnWidth;
   //如果距离小于删除按钮的1/2,不显示删除按钮
   var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "px" : "left:0px";
   //获取手指触摸的是哪一项
   var index = e.target.dataset.index;
   var list = this.data.list;
   list[index].txtStyle = txtStyle;
   //更新列表的状态
   this.setData({
    list: list
   });
  }
 },
 //获取元素自适应后的实际宽度
 getEleWidth: function (w) {
  var real = 0;
  try {
   var res = wx.getSystemInfoSync().windowWidth;
   var scale = (750 / 2) / (w / 2);//以宽度750px设计稿做宽度的自适应
   // console.log(scale);
   real = Math.floor(res / scale);
   return real;
  } catch (e) {
   return false;
   // Do something when catch error
  }
 },
 initEleWidth: function () {
  var delBtnWidth = this.getEleWidth(this.data.delBtnWidth);
  this.setData({
   delBtnWidth: delBtnWidth
  });
 },
 //点击删除按钮事件
 delItem: function (e) {
  //获取列表中要删除项的下标
  var index = e.target.dataset.index;
  var list = this.data.list;
  //移除列表中下标为index的项
  list.splice(index, 1);
  //更新列表的状态
  this.setData({
   list: list
  });
 },
 //测试临时数据
 tempData: function () {
  var list = [
   {
    rank: "1",
    txtStyle: "",
    icon: "/images/my.png",
    name: "李飞",
    pace: "23456",
   },
   {
    rank: "2",
    txtStyle: "", 
    icon: "/images/my.png",
    name: "张叶",
    pace: "23450",
   },
   {
    rank: "3",
    txtStyle: "",
    icon: "/images/my.png",
    name: "王小婷",
    pace: "22345",
   },
   {
    rank: "4",
    txtStyle: "",
    icon: "/images/my.png",
    name: "袁经理",
    pace: "21687",
   },
   {
    rank: "5",
    txtStyle: "",
    icon: "/images/my.png",
    name: "陈雅婷",
    pace: "21680",
   },
   {
    rank: "6",
    txtStyle: "",
    icon: "/images/my.png",
    name: "许安琪",
    pace: "20890",
   },
   {
    rank: "7",
    txtStyle: "",
    icon: "/images/my.png",
    name: "里俊飞",
    pace: "20741",
   },
   {
    rank: "8",
    txtStyle: "",
    icon: "/images/my.png",
    name: "李小俊",
    pace: "19511",
   },
   {
    rank: "9",
    txtStyle: "",
    icon: "/images/my.png",
    name: "陈俊飞",
    pace: "19501",
   },]
  //
  this.setData({
   list: list
  });
 }
})

以上就是使用微信小程序怎么实现一个运动步数排行功能,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。


标题名称:使用微信小程序怎么实现一个运动步数排行功能
网站网址:http://bzwzjz.com/article/pesjpg.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 营销型网站建设 高端网站建设 网站设计 四川成都网站设计 成都网站建设 重庆电商网站建设 网站设计制作 成都网站设计 成都网站制作公司 品牌网站建设 营销网站建设 重庆网站建设 网站制作 网站建设方案 成都网站建设 成都网站建设 成都定制网站建设 企业网站设计 网站建设 成都网站设计 定制网站设计 成都网站建设公司