小程序实现点击tab切换左右滑动


Posted in Javascript onNovember 16, 2020

本文实例为大家分享了小程序实现点击tab切换左右滑动的具体代码,供大家参考,具体内容如下

wxml

<scroll-view scroll-x="true" class="navbar-box">
 <block wx:for="{{recordMain}}" wx:for-index="idx" wx:for-item="navItem" wx:key="idx">
 <view class="nav-item " data-current="{{idx}}" bindtap="switchNav">
  <text class="{{currentTab == idx ? 'active' : ''}}">{{navItem.title}}</text>
 </view>
 </block>
</scroll-view>

<swiper style="margin-top:80rpx;height:{{winHeight - 40}}px;" class="tab-box" current="{{currentTab}}" duration="300" data-current="{{idx}}" bindchange="switchTab">
 <swiper-item style="height:100%;overflow-y:scroll" wx:for="{{[0,1,2,3,4,5]}}" wx:for-item="tabItem" wx:for-index="idx" wx:key="idx" class="tab-cnetent">
 <block wx:for="{{tabContent}}" wx:key=" " bindtap='myOrderDetails'>
  <!-- 列表 -->
  <view class='listBox'> 
   <view class='listTop'>
   <image src='{{item.goodsImg}}' class='goodsImg'></image>
   <view class='infor'>
    <view class=''>
    <text class='name'>{{item.name}}</text>
    <text class='price'>¥{{item.price}}</text>
    </view>
    <view class=''>
    <text class='choose'>{{item.choose}}</text>
    <text class='number'>×{{item.number}}</text>
    </view>
   </view>
   </view>
   <view class='listBottom'>
   <view>共{{item.number}}件商品,合计:¥{{item.allPrice}}</view>
   <view class='status'>
    <button>查看物流</button>
    <button>确认收货</button>
   </view>
   </view> 
  </view>
 </block>
 </swiper-item>
</swiper>

wxss

::-webkit-scrollbar {
 width: 0;
 height: 0;
 color: transparent;
}

.navbar-box {
 height: 70rpx;
 line-height: 70rpx;
 position: fixed;
 top: 0rpx;
 background: white
}

.nav-item {
 display: inline-block;
 width: 16.6%;
 text-align: center;
}

.nav-item text {
 padding-bottom: 10rpx;
}
 
page {
 background: #f2f2f2;
 font-size: 28rpx;
}

.active {
 color: #a53533;
 border-bottom: 4rpx solid #a53533;
 box-sizing: border-box;
}

.menu {
 font-size: 28rpx;
 width: 100%;
 /* overflow-x: scroll; */
 border-bottom: 20rpx solid #f2f2f2;
 padding: 30rpx 30rpx 0rpx 30rpx;
 box-sizing: border-box;
 display: flex;
 justify-content: space-between;
 position: fixed;
 top: 0rpx;
 z-index: 999;
 background: white;
}

.chooseNav {
 padding-bottom: 10rpx;
}

.listBox {
 padding: 30rpx;
 width: calc(100% - 60rpx);
 margin-left: 30rpx;
 margin-top: 30rpx;
 background: white;
 box-sizing: border-box;
 border-radius: 8rpx;
} 

.listTop {
 display: flex;
 justify-content: space-between;
}

.goodsImg {
 width: 200rpx;
 height: 200rpx;
 margin-right: 20rpx;
}

.infor {
 flex: 1;
 margin-top: 80rpx;
 font-size: 26rpx;
 color: #666;
}

.infor view {
 width: 100%;
 display: flex;
 justify-content: space-between;
}

.infor view:nth-of-type(2) {
 font-size: 24rpx;
}

.name, .choose {
 font-weight: 600;
 display: inline-block;
 overflow: hidden;
 text-overflow: ellipsis;
 white-space: nowrap;
 width: 320rpx;
}

.price, .number {
 padding: 5rpx 10rpx;
 box-sizing: border-box;
}

.listBottom {
 text-align: right;
}

button::after {
 border: none;
}

.status button {
 display: inline-block;
 background: white;
 border: 1px solid #dedede;
 border-radius: 66rpx;
 font-size: 24rpx;
 margin-left: 20rpx;
 color: #666;
 padding: 0rpx 30rpx;
 box-sizing: border-box;
 height: 50rpx;
 line-height: 45rpx;
 margin-top: 20rpx;
}

wxjs

Page({ 
 data: {
 recordMain: [
  
  {
  title: "全部"
  },
  {
  title: "待付款"
  },
  {
  title: "待发货"
  },
  {
  title: "待发货"
  }, {
  title: "已完成"
  },
  {
  title: "已取消"
  },
 ],
 tabContent: [
  {
  goodsImg: '/img/goods.png',
  name: '阿莎玛沙阿莎玛沙发阿莎玛沙发阿莎玛沙发阿莎玛沙莎玛沙发发',
  price: "666",
  choose: '已选:全新,16期',
  number: '32',
  allPrice: '888'
  },
 ],
 currentTab: 0,
 navScrollLeft: 0,
 winWidth: 0,
 winHeight: 0, 
 },
 // 事件处理函数
 onLoad: function () {
 var that = this; 
 /** 获取系统信息*/
 wx.getSystemInfo({
  success: function (res) {
  that.setData({
   winWidth: res.windowWidth,
   winHeight: res.windowHeight,
  });
  }
 });
 },
 // 滑动事件
 // 点击标题切换当前页时改变样式
 switchNav:function(e) {
 console.log(e.currentTarget.dataset.current)
 var that = this
 var cur = e.currentTarget.dataset.current;
 if (that.data.currentTab == cur) {
  return false;
 } else {
  that.setData({
  currentTab: cur
  })
 }
 },
 // 滚动切换标签样式 
 switchTab: function(e) {
 console.log(e) 
 var that = this; 
 that.setData({
  currentTab: e.detail.current
 }); 

 if (e.detail.current == 0) {
  console.log(0)
 } 
 else if (e.detail.current == 1) {
  console.log(11)
 } 
 else if (e.detail.current == 2) {
  console.log(2222) 
 } 
 else if (e.detail.current == 3) {
  console.log(33333)
 } 
 else if (e.detail.current == 4) {
  console.log(44444444)
 } 
 else if (e.detail.current == 5) {
  console.log(55555)
 } 
 }
})

小程序实现点击tab切换左右滑动

为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
jQuery函数的等价原生函数代码示例
May 27 Javascript
JS实现根据出生年月计算年龄
Jan 10 Javascript
escape编码与unescape解码汉字出现乱码的解决方法
Jul 02 Javascript
asp.net+js实现金额格式化
Feb 27 Javascript
深入理解JavaScript系列(49):Function模式(上篇)
Mar 04 Javascript
jquery广告无缝轮播实例
Jan 05 Javascript
Angular.JS实现无限级的联动菜单(使用demo)
Feb 08 Javascript
jquery仿微信聊天界面
May 06 jQuery
Angular2之二级路由详解
Aug 31 Javascript
微信小程序中button去除默认的边框实例代码
Aug 01 Javascript
vue中使用WX-JSSDK的两种方法(推荐)
Jan 18 Javascript
vue单元格多列合并的实现
Nov 26 Vue.js
微信小程序实现滚动Tab选项卡
Nov 16 #Javascript
小程序实现tab标签页
Nov 16 #Javascript
vue+Element-ui实现登录注册表单
Nov 17 #Javascript
Vue+Element-U实现分页显示效果
Nov 15 #Javascript
vue+Element-ui前端实现分页效果
Nov 15 #Javascript
vue+Element-ui实现分页效果
Nov 15 #Javascript
vue实现抽屉弹窗效果
Nov 15 #Javascript
You might like
php中serialize序列化与json性能测试的示例分析
2013/04/27 PHP
php计算税后工资的方法
2015/07/28 PHP
phpcms的分类名称和类别名称的调用
2017/01/05 PHP
PHP PDO数据库操作预处理与注意事项
2019/03/16 PHP
php实现银联商务公众号+服务窗支付的示例代码
2019/10/12 PHP
获取当前网页document.url location.href区别总结
2008/05/10 Javascript
javascript优先加载笔记代码
2008/09/30 Javascript
jquery 操作单选框,复选框,下拉列表实现代码
2009/10/27 Javascript
Javascript在IE或Firefox下获取鼠标位置的代码
2009/12/18 Javascript
如何用jQuery实现ASP.NET GridView折叠伸展效果
2015/09/26 Javascript
jQuery焦点图插件SaySlide
2015/12/21 Javascript
完美的js div拖拽实例代码
2016/09/24 Javascript
vue 过滤器filter实例详解
2018/03/14 Javascript
jQuery实现的淡入淡出图片轮播效果示例
2018/08/29 jQuery
ES6 Object方法扩展的应用实例分析
2019/06/25 Javascript
在layui中layer弹出层点击事件无效的解决方法
2019/09/05 Javascript
vue实现公告栏文字上下滚动效果的示例代码
2020/06/16 Javascript
按日期打印Python的Tornado框架中的日志的方法
2015/05/02 Python
python实现比对美团接口返回数据和本地mongo数据是否一致示例
2019/08/09 Python
pytorch 改变tensor尺寸的实现
2020/01/03 Python
基于Python绘制美观动态圆环图、饼图
2020/06/03 Python
Python while true实现爬虫定时任务
2020/06/08 Python
美国女鞋品牌:naturalizer(娜然)
2016/08/01 全球购物
介绍一下EJB的分类及其各自的功能及应用
2016/08/23 面试题
自动化专业个人求职信范文
2013/11/29 职场文书
老同学聚会感言
2014/02/23 职场文书
搞笑的获奖感言
2014/08/16 职场文书
2015年安全工作总结范文
2015/04/02 职场文书
党员志愿者服务倡议书
2015/04/29 职场文书
2016年公司“3.12”植树节活动总结
2016/03/16 职场文书
婚前协议书怎么写,才具有法律效力呢 ?
2019/06/28 职场文书
告诉你创业计划书的8个实用技巧
2019/07/12 职场文书
如何利用python和DOS获取wifi密码
2021/03/31 Python
纯CSS如何禁止用户复制网页的内容
2021/11/01 HTML / CSS
Javascript中Microtask和Macrotask鲜为人知的知识点
2022/04/02 Javascript
SQL Server的存储过程与触发器以及系统函数和自定义函数
2022/04/10 SQL Server