700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 微信小程序实现滑动tab切换和点击tab切换并显示相应的数据(附源代码)

微信小程序实现滑动tab切换和点击tab切换并显示相应的数据(附源代码)

时间:2024-07-14 04:23:56

相关推荐

微信小程序实现滑动tab切换和点击tab切换并显示相应的数据(附源代码)

微信小程序开发交流qq群 581478349

承接微信小程序开发。扫码加微信。

正文:

先上效果图:

这里主要用到了swiper组件和三目运算,直接上代码, 样式只有三个class,简单粗暴,懒的小伙伴们可以直接拿来用,喜欢的点个支持

<view><view class="swiper-tab"><view class="bre swiper-tab-list {{tab==0 ? 'on' : ''}}" data-current="0" bindtap="tab_click">图文详情</view><view class="swiper-tab-list {{tab==1 ? 'on' : ''}}" data-current="1" bindtap="tab_click">产品参数</view></view><swiper current="{{tab}}" class="swiper-box" duration="300" style="height:{{winHeight - 31}}px" bindchange="tab_slide"><swiper-item>图文详情</swiper-item><swiper-item>产品参数</swiper-item></swiper></view>

Page({data: {tab: 0},tab_slide: function (e) {//滑动切换tab var that = this;that.setData({ tab: e.detail.current });},tab_click: function (e) {//点击tab切换var that = this;if (that.data.tab === e.target.dataset.current) {return false;} else {that.setData({tab: e.target.dataset.current})}},})

.swiper-tab{ width: 100%; border-bottom: 2rpx solid #eee; text-align: center; line-height: 80rpx;background: #fff;font-size: 14px;} .on{ color: #dd2727; border-bottom: 5rpx solid #dd2727;} .swiper-tab-list{ font-size: 29rpx; display: inline-block; width: 49.5%; color: #333; }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。