小程序上tab点击切换效果怎么实现,方法是什么
Admin 2022-06-09 群英技术资讯 765 次浏览
这篇文章主要讲解了“小程序上tab点击切换效果怎么实现,方法是什么”,文中的讲解内容简单、清晰、详细,对大家学习或是工作可能会有一定的帮助,希望大家阅读完这篇文章能有所收获。下面就请大家跟着小编的思路一起来学习一下吧。本文实例为大家分享了小程序实现点击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)
}
}
})

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
问题:TypeScript 中为函数添加多个签名后,依然需要添加相应的代码来判断并从不同的签名参数列表中获取对应的参数。过去常见的写法:function refEventEmitter(event?: string): void;function refEventEmitter(event: string, callb
在数组的使用中我们通常会有数组的过滤的需求,比如值在某个范围内的数字,用来组成一个新的数组,这就用到了数组的过滤,下面这篇文章主要给大家介绍了关于JS数组中filter方法使用的相关资料,需要的朋友可以参考下
这篇文章要实现的需求是打开其他项目并传数据的的内容,那么vue如何向其他项目页面传数据?下面给大家介绍不跨域和跨域这两种情况下的方法,感兴趣的朋友接下来跟随小编来参考一下吧。
这篇文章主要介绍了Vue2的diff算法的相关资料,帮助大家更好的理解和使用vue框架,感兴趣的朋友可以了解下
property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008