小程序中tab切换页面效果如何做,代码是什么
Admin 2022-08-12 群英技术资讯 1082 次浏览
本文实例为大家分享了小程序实现tab更换页面效果的具体代码,供大家参考,具体内容如下
.wxml
<scroll-view scroll-x="true" class="ip_tab_comtainer"> <view class="ip_tab_comtainer_padd"></view> <block wx:for="{{ips}}" wx:for-item="ip" wx:key="{{ip.id}}"> <view class="{{ip.isSelect?'ip_tab_item_s':'ip_tab_item_n'}}" bindtap="onIpItemClick" wx:key="" data-item="{{ip}}"> {{ip.title}} </view> </block> <view class="ip_tab_comtainer_padd"></view> </scroll-view> <view class='content'> <block> <view class="content1" wx:if="{{content=='日统计'}}">{{content}}</view> <view class="content2" wx:if="{{content=='月统计'}}">{{content}}</view> <view class="content3" wx:if="{{content=='年统计'}}">{{content}}</view> </block> </view>
.wxss
page{ width: 100%; height: 100%; } .ip_tab_comtainer { width: 100%; background-color: #F5F5F5; padding: 20rpx 0 0; white-space: nowrap; } .ip_tab_comtainer_padd { display: inline-block; width: 5%; } .ip_tab_item_s { width: 30%; display: inline-block; line-height: 40rpx; text-align: center; color: #91daf9; font-size: 28rpx; overflow: hidden; background-color: #ffffff; border: 1px solid #91daf9; } .ip_tab_item_n { width: 30%; display: inline-block; text-align: center; line-height: 40rpx; color: #353535; background-color: #ffffff; font-size: 28rpx; text-align: center; overflow: hidden; text-overflow: ellipsis; border-radius: 4rpx; border: 1px solid #CCCCCC; } /** 去除横向滚动条 */ ::-webkit-scrollbar { width: 0; height: 0; color: transparent; } .content{ width: 100%; height: 100%; display: flex; background-color: #CCCCCC; } .content1{ width: 100%; height: 100%; display: flex; background-color: #6b10e0; } .content2{ width: 100%; height: 100%; display: flex; background-color: #d41515; } .content3{ width: 100%; height: 100%; display: flex; background-color: #1ac729; }
.js
/** * 页面的初始数据 */ data: { ips: [ { id: "1", title: "日统计", isSelect:true }, { id: "2", title: "月统计", isSelect: false}, { id: "3", title: "年统计", isSelect: false}, ], content: "日统计" }, /** * item点击事件 */ onIpItemClick: function (event) { console.log(event); var id = event.currentTarget.dataset.item.id; var curIndex = 0; for (var i = 0; i < this.data.ips.length; i++) { if (id == this.data.ips[i].id) { this.data.ips[i].isSelect = true; curIndex = i; } else { this.data.ips[i].isSelect = false; } } this.setData({ content: this.data.ips[curIndex].title, ips: this.data.ips, }); },
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
目录一、背景简介二、原型对象和对象的关系二、使用 prototype 和 proto 实现继承三、使用prototype和proto实现继承四、通过原型链访问对象的方法和属性五、其他方式实现继
在vue3.x中vuex调取值在html代码里可以直接使用vue2.x的方法,但是在js里与vue2.x就有了那么一丢丢的不同,下面这篇文章主要给大家介绍了关于Vue3中Vuex详细使用的相关资料,需要的朋友可以参考下
这篇文章给大家分享用JS怎样实现鼠标小尾巴的特效的内容,实现原理其实并不困难,本文有代码供大家参考,感兴趣的朋友可以参考,接下来跟随小编一起来了解看看吧。
这篇文章主要介绍了JS实现元素的拖动与占位功能,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
vue中怎样使用echarts?echarts图标库简单易上手,而且能很好满足项目开发的图标需求,所以掌握echarts的用法是很有必要的。下面我们就一起来了解一下echarts使用步骤。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008