小程序实现页面顶部选项卡效果
2018-11-06 15:00
806 查看
本文实例为大家分享了小程序实现选项卡效果的具体代码,供大家参考,具体内容如下
效果图:
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 }); } })
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- 微信小程序开发之实现选项卡(窗口顶部TabBar)页面切换
- 微信小程序实现顶部普通选项卡效果(非swiper)
- 微信小程序开发之选项卡(窗口顶部/底部TabBar)页面切换
- 微信小程序实现顶部选项卡(swiper)
- jQuery实现页面顶部显示的进度条效果完整实例
- AjaxPanel自定义控件实现页面无刷新数据交互(做了个示例程序, 效果确实比较Cool, 用法非常简单! )(示例代码下载)
- 微信小程序 实现tabs选项卡效果实例代码
- HTML页面实现返回顶部效果 go to top
- 小程序实现选项卡效果代码
- AjaxPanel自定义控件实现页面无刷新数据交互(做了个示例程序, 效果确实比较Cool, 用法非常简单!
- JS实现部分HTML固定页面顶部随屏滚动效果
- 用jquery实现小火箭到页面顶部的效果
- Android 实现页面顶部下拉、底部上拉 沿着Y轴缩放效果
- jquery实现页面常用的返回顶部效果
- AjaxPanel自定义控件实现页面无刷新数据交互(做了个示例程序, 效果确实比较Cool, 用法非常简单! )(示例代码下载)
- JS实现回到页面顶部动画效果 2016.03.23
- AjaxPanel自定义控件实现页面无刷新数据交互(做了个示例程序, 效果确实比较Cool, 用法非常简单! )(示例代码下载)
- JS实现页面回到顶部效果
- 微信小程序开发之选项卡(窗口顶部TabBar)页面切换