本文实例为大家分享了小程序实现选项卡效果的具体代码,供大家参考,具体内容如下
效果图:
github源码下载
<!--index.wxml--> <view class="swiper-tab" > <view bindtap="swithnav" wx:for="{{tabcont}}" wx:key="item.index" class="swiper-tab-list {{currenttab==item.index?'active':''}}" data-current='{{item.index}}' >{{item.title}}</view> </view> <swiper class="swiper-box" current="{{currenttab}}" duration="300" style="height:400px" bindchange="getcurrenttab" data-current='6' > <swiper-item wx:for="{{tabcont}}" wx:key="item.index"> <image src='{{item.pic}}'></image> <view>{{item.title}}</view> </swiper-item> </swiper>
css:
/**index.wxss**/ /**index.wxss**/ .swiper-tab { line-height: 80rpx; border: 1px solid #ccc; display: flex; justify-content: space-around; align-items: center; } .swiper-tab-list { font-size: 30rpx; color: #777; text-align: center; } .active { color: #da7c0c; border-bottom: 5rpx solid #da7c0c; } .swiper-box { display: block; height: 100%; width: 100%; overflow: hidden; } .swiper-box view { text-align: center; } image { width: 100%; }
js:
page({ /** * 页面的初始数据 */ data: { currenttab:0, tabcont: [{ "title": "tab1", "pic": "../../img/1.jpg", "index": "0" }, { "title": "tab2", "pic": "../../img/2.jpg", "index": "1" }, { "title": "tab3", "pic": "../../img/3.jpg", "index": "2" }, { "title": "tab4", "pic": "../../img/2.jpg", "index": "3" }, { "title": "tab5", "pic": "../../img/2.jpg", "index": "4" }, { "title": "tab6", "pic": "../../img/2.jpg", "index": "5" }, { "title": "tab7", "pic": "../../img/2.jpg", "index": "6" }, { "title": "tab8", "pic": "../../img/2.jpg", "index": "7" }, { "title": "tab9", "pic": "../../img/2.jpg", "index": "8" }], }, /** * 生命周期函数--监听页面加载 */ onload: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onready: function () { }, /** * 生命周期函数--监听页面显示 */ onshow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onhide: function () { }, /** * 生命周期函数--监听页面卸载 */ onunload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onpulldownrefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onreachbottom: function () { }, /** * 用户点击右上角分享 */ onshareappmessage: function () { }, // swiper滑动时触发bindchange事件,获取事件对象e获取当前所在滑块的 index,并将其更新至data的currenttab中,视图渲染通过判断currenttab的让对应的tab hover。 getcurrenttab:function(e){ console.log(e.detail.current); var that = this; this.setdata({ currenttab:e.detail.current }); // console.log("11111"+this.data.currenttab); }, swithnav:function(e){ var that = this; that.setdata({ currenttab:e.target.dataset.current }); } })
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
selenium + ajax抓取英雄联盟全部英雄的详细信息及多线程保存全部皮肤图片到本地
网友评论