小程序实现点击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 相关文章推荐
js同时按下两个方向键
Dec 01 Javascript
node.js中的path.sep方法使用说明
Dec 08 Javascript
JavaScript中创建字典对象(dictionary)实例
Mar 31 Javascript
JS实现带缓冲效果打开、关闭、移动一个层的方法
May 09 Javascript
JQuery包裹DOM节点的方法
Jun 11 Javascript
在Linux系统中搭建Node.js开发环境的简单步骤讲解
Jan 26 Javascript
jQuery使用$获取对象后检查该对象是否存在的实现方法
Sep 04 Javascript
实例讲解JavaScript中call、apply、bind方法的异同
Sep 13 Javascript
详解webpack模块化管理和打包工具
Apr 21 Javascript
vue实现动态添加数据滚动条自动滚动到底部的示例代码
Jul 06 Javascript
node.js制作一个简单的登录拦截器
Feb 10 Javascript
vue集成一个支持图片缩放拖拽的富文本编辑器
Jan 29 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页码形式分页函数支持静态化地址及ajax分页
2014/03/28 PHP
WAF的正确bypass
2017/01/05 PHP
PHP赋值的内部是如何跑的详解
2019/01/13 PHP
php-7.3.6 编译安装过程
2020/02/11 PHP
PHP Beanstalkd消息队列的安装与使用方法实例详解
2020/02/21 PHP
Node.js中AES加密和其它语言不一致问题解决办法
2014/03/10 Javascript
js去除输入框中所有的空格和禁止输入空格的方法
2014/06/09 Javascript
我的NodeJs学习小结(一)
2014/07/06 NodeJs
JQuery的Ajax中Post方法传递中文出现乱码的解决方法
2014/10/21 Javascript
使用jQuery在移动页面上添加按钮和给按钮添加图标
2015/12/04 Javascript
分享JS代码实现鼠标放在输入框上输入框和图片同时更换样式
2016/09/01 Javascript
浅谈js原生拖放
2016/11/21 Javascript
javascript 使用正则test( )第一次是 true,第二次是false
2017/02/22 Javascript
Node.js读取文件内容示例
2017/03/07 Javascript
基于vue.js的分页插件详解
2017/11/27 Javascript
在React项目中使用Eslint代码检查工具及常见问题
2018/10/10 Javascript
小程序使用wxs解决wxml保留2位小数问题
2019/12/13 Javascript
基于JavaScript判断两个对象内容是否相等
2020/01/10 Javascript
Django Rest framework之认证的实现代码
2018/12/17 Python
浅谈PySpark SQL 相关知识介绍
2019/06/14 Python
TensorFLow 变量命名空间实例
2020/02/11 Python
浅谈Tensorflow加载Vgg预训练模型的几个注意事项
2020/05/26 Python
python编写一个会算账的脚本的示例代码
2020/06/02 Python
用Python制作mini翻译器的实现示例
2020/08/17 Python
一款基于css3和jquery实现的动画显示弹出层按钮教程
2015/01/04 HTML / CSS
新加坡网上花店:FlowerAdvisor新加坡
2018/10/05 全球购物
校园之声广播稿
2014/01/31 职场文书
学生请假条
2014/04/11 职场文书
村庄环境整治方案
2014/05/15 职场文书
办公室文员岗位职责范本
2014/06/12 职场文书
大学教师个人总结
2015/02/10 职场文书
酒店财务经理岗位职责
2015/04/08 职场文书
Python实现天气查询软件
2021/06/07 Python
纯CSS3实现div按照顺序出入效果
2021/07/15 HTML / CSS
详解Python中的for循环
2022/04/30 Python
MySQL transaction事务安全示例讲解
2022/06/21 MySQL