首页 技术 正文
技术 2022年11月17日
0 收藏 404 点赞 4,357 浏览 2503 个字

小程序写tab和swiper切换结合效果

实现代码如下: 
wxml页面

<scroll-view scroll-x=”true” class=”weui-navbar”>
<block wx:for-items=”{{tabs}}”>
<view id=”{{index}}” class=”{{activeIndex == index ?’item_on’:”}} default-item” bindtap=”tabClick” style=”width:{{tabW}}px”>
{{item}}
</view>
</block>
<view class=”weui-navbar-slider” style=”transform:translateX({{slideOffset}}px);”></view>
</scroll-view>
<view class=”rec” />
<swiper current=”{{activeIndex}}” class=”swiper-box” duration=”100″ bindchange=”bindChange”>
<swiper-item class=”swiper-item”>
<view class=”slide-view”>tab0</view>
</swiper-item>
<swiper-item class=”swiper-item”>
<view class=”slide-view”>tab1</view>
</swiper-item>
<swiper-item class=”swiper-item”>
<view class=”slide-view”>tab2</view>
</swiper-item>
<swiper-item class=”swiper-item”>
<view class=”slide-view”>tab3</view>
</swiper-item>
<swiper-item class=”swiper-item”>
<view class=”slide-view”>tab4</view>
</swiper-item>
<swiper-item class=”swiper-item”>
<view class=”slide-view”>tab5</view>
</swiper-item>
<swiper-item class=”swiper-item”>
<view class=”slide-view”>tab6</view>
</swiper-item>
</swiper>

wxss样式:

page {
height: 100%;
}
view , scroll-view{
padding: 0px;
margin: 0px;
}
.weui-navbar{
width: 100%;
position: fixed;
border-bottom: 1px solid #00bba1;
box-sizing: border-box;
white-space: nowrap;
z-index: 100;
background: white;
}
.rec{
width: 100%;
height: 7%;
}
.weui-navbar .default-item{
/*width:25%;*/
display: inline-block;
text-align: center;
font-size: 32rpx;
box-sizing: border-box;
height: 7%;
padding-bottom: 20rpx;
}
.weui-navbar .item_on{
color: #00bba1;
}
.weui-navbar-slider{
position: absolute;
width: 160rpx;
height: 2px;
content:””;
background: #00bba1;
bottom: 0px;
left: 12.5rpx;
transition: transform .3s;
}
.swiper-box{
height: 900px;
border-bottom: 1px solid #d1d1d1;
}
.swiper-box .swiper-item{
text-align: center;
padding-top: 200rpx;
height: 100%;
}

//index.js
//获取应用实例
var app = getApp();
var mtabW;
Page({
data: {
tabs:[“综合与绘画”,”艺术喷漆”,”泥塑”,”纸面绘画”,”布面绘画”,”中国油画”,”水墨画”],
activeIndex:0,
slideOffset:0,
tabW:0
},
//事件处理函数
onLoad: function () {
var that = this;
wx.getSystemInfo({
success: function (res) {
mtabW = res.windowWidth / 4; //设置tab的宽度
that.setData({
tabW:mtabW
})
}
});

},
bindViewTap: function() {
wx.navigateTo({
url: ‘../logs/logs’
})
},
tabClick:function(e){
var that = this;
var idIndex = e.currentTarget.id;
var offsetW = e.currentTarget.offsetLeft; //2种方法获取距离文档左边有多少距离
this.setData({
activeIndex:idIndex,
slideOffset:offsetW
});
},
bindChange:function(e){
var current = e.detail.current;
if((current+1)%4 == 0){

}
var offsetW = current * mtabW; //2种方法获取距离文档左边有多少距离
this.setData({
activeIndex:current,
slideOffset:offsetW
});

}

})

———————
作者:花生地瓜
来源:CSDN
原文:https://blog.csdn.net/u013018357/article/details/64922923

上一篇: rust borrow and move
下一篇: 集训Day5
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,761
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838