微信小程序?qū)Ш綑诟S滑動(dòng)效果的實(shí)現(xiàn)代碼
效果圖

.wxml
<view class='tabBar'>
<view class='tabItem wx:if="{{tabClick===0?"click":""}}"' bindtap='clickTab' data-index='0'>tab1</view>
<view class='tabItem wx:if="{{tabClick===1?"click":""}}"' bindtap='clickTab' data-index='1'>tab2 </view>
<view class='tabItem wx:if="{{tabClick===2?"click":""}}"' bindtap='clickTab' data-index='2'>tab3 </view>
<view class='underline' animation="{{animationData}}" style='left:{{isLeft}}'></view>
</view>
.wxss
.tabBar{
height: 80rpx;
background-color:#50B7EA;
width: 100%;
font-size: 28rpx;
color: rgba(255,255,255,0.50);
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
z-index: 997;
}
.tabItem{
width: 33.333%;
display: flex;
align-content: center;
justify-content: center;
position: relative;
height: 100%;
font-size: 28rpx;
}
.click{
color: white;
}
.underline{
position: absolute;
content: '';
width: 84rpx;
height: 3px;
background-color:white;
bottom: 0;
}
.js
data:{
tabClick: 0,
animationData: {},
isLeft: '12%'
},
swiperTab: function (e) {
var that = this;
var index = e.detail.current
console.log(e.detail.current)
var animation = wx.createAnimation({
duration: 1000,
timingFunction: "ease",
})
this.animation = animation
if (index === 0) {
animation.translate(0, 0).step();
that.setData({
animationData: animation.export()
})
that.setData({
tabClick: e.detail.current
});
} else if (index === 1) {
var w = wx.getSystemInfoSync().windowWidth;
w = w * 0.32
animation.translate(w, 0).step();
that.setData({
animationData: animation.export()
})
that.setData({
tabClick: e.detail.current
});
} else if(index === 2){
var w = wx.getSystemInfoSync().windowWidth;
w = w * 0.65
animation.translate(w, 0).step();
that.setData({
animationData: animation.export()
})
that.setData({
tabClick: e.detail.current
});
}
},
總結(jié)
以上所述是小編給大家介紹的微信小程序?qū)Ш綑诟S滑動(dòng)效果的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
相關(guān)文章
JS面向?qū)ο蟮某绦蛟O(shè)計(jì)相關(guān)知識(shí)小結(jié)
這篇文章主要介紹了JS面向?qū)ο蟮某绦蛟O(shè)計(jì),現(xiàn)在很多代碼都是基于面向?qū)ο髮?shí)現(xiàn),需要的朋友可以參考下2018-05-05
js中繼承的幾種用法總結(jié)(apply,call,prototype)
本篇文章主要介紹了js中繼承的幾種用法總結(jié)(apply,call,prototype) 需要的朋友可以過來(lái)參考下,希望對(duì)大家有所幫助2013-12-12
在JavaScript中獲取請(qǐng)求的URL參數(shù)
在ASP.NET后臺(tái)代碼中,對(duì)于這樣的URL請(qǐng)求地址:http://www.abc.com?id=001,我們可以通過Request.QueryString["id"]的方法很容易的獲取到URL中請(qǐng)求的參數(shù)的值,但是要在前臺(tái)js代碼中獲取請(qǐng)求的參數(shù)的值,應(yīng)該怎么做呢?2010-12-12
js神秘的電報(bào)密碼 哈弗曼編碼實(shí)現(xiàn)
這篇文章主要介紹了js神秘的電報(bào)密碼 哈弗曼編碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09
JavaScript遞歸函數(shù)解“漢諾塔”算法代碼解析
這篇文章主要介紹了JavaScript遞歸函數(shù)解“漢諾塔”算法代碼解析,需要的朋友可以參考下2018-07-07
JS簡(jiǎn)單實(shí)現(xiàn)自定義右鍵菜單實(shí)例
本篇文章主要介紹了JS簡(jiǎn)單實(shí)現(xiàn)自定義右鍵菜單實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-05-05
JavaScript數(shù)據(jù)結(jié)構(gòu)Number
這篇文章主要介紹了JavaScript數(shù)據(jù)結(jié)構(gòu)Number,Number?是JavaScript的基本數(shù)據(jù)結(jié)構(gòu),是對(duì)應(yīng)數(shù)值的應(yīng)用類型,下文給大家分享JavaScript使用?Number?的常見問題,需要的朋友可以參考一下2022-02-02
javascript html實(shí)現(xiàn)網(wǎng)頁(yè)版日歷代碼
這篇文章主要介紹了javascript html實(shí)現(xiàn)網(wǎng)頁(yè)版日歷代碼,需要的朋友可以參考下2016-03-03

