微信小程序?qū)崿F(xiàn)原生步驟條
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)原生步驟條的具體代碼,供大家參考,具體內(nèi)容如下
效果

(步驟條顏色不對(duì)是錄制工具的問題)
思路
其實(shí)與輪播圖類似,使用了兩個(gè)并排的輪播容器,在滑動(dòng)監(jiān)聽后,給圖片加上移動(dòng)和縮放動(dòng)畫。
擴(kuò)展
可以用于標(biāo)簽頁的切換。
vue與微信小程序有類似的地方,所以微信小程序做出的效果,原理也可用于vue在網(wǎng)頁上的應(yīng)用。
代碼
wxml
<view class='window'>
<view class='content' bindtouchstart='touchS' bindtouchend='touchE' style='left:{{left}}rpx'>
<view wx:for="{{list}}">
<!-- 時(shí)間線 -->
<view class='pot'>
<view class='{{index == 0?"blank":"line"}}'></view>
<view class='circle' style='background:{{show_index == index?"orange":""}}'></view>
<view class='{{index == length - 1?"blank":"line"}}'></view>
</view>
<!-- 圖片 -->
<view class='pic_container'>
<image class='pic' style='{{show_index != index?"transform:scale(0.5,0.5)":""}}' src="../../images/{{index+1}}.jpg"></image>
</view>
</view>
</view>
</view>
wxss
.window{
width: 450rpx;
background-color: #eee;
padding: 25rpx;
position: relative;
overflow: hidden;
margin: 0 auto;
border-radius: 20rpx;
}
.content{
display: flex;
position: relative;
transition: all 0.5s;
}
.content>view{
display: flex;
flex-direction: column;
align-items: center;
}
.pot{
width: 450rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
.circle{
border-radius: 100%;
height: 20rpx;
width: 20rpx;
border:4rpx solid orange;
}
.line{
height: 4rpx;
width: 50%;
background: orange;
}
.blank{
height: 4rpx;
width: 50%;
}
.pic_container{
width: 450rpx;
height: 450rpx;
display: flex;
justify-content:center;
align-items: center;
}
.pic{
width: 400rpx;
height: 400rpx;
transition: all 0.5s;
}
js
Page({
data: {
list: ['1', '2', '3'],
left:0,
show_index:0
},
onLoad: function () {
this.setData({
length:this.data.list.length
})
},
touchS:function(e){
var that = this;
this.data.start = e.touches[0].pageX;
this.data.start_left = this.data.left;
},
touchE:function(e){
var that = this;
this.data.end = e.changedTouches[0].pageX;
var distance = this.data.end - this.data.start;
//左滑
if (distance <= -40 && this.data.left > -900) {
this.setData({
left: that.data.start_left - 450,
show_index:++ this.data.show_index
})
}
//不滑
else if(distance <= 40){
this.setData({
left: that.data.start_left,
})
}
//右滑
else if (distance > 40 && this.data.left < 0) {
this.setData({
left: that.data.start_left + 450,
show_index: --this.data.show_index
})
}
}
})
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
通過掃小程序碼實(shí)現(xiàn)網(wǎng)站登陸功能
這篇文章主要介紹了通過掃小程序碼實(shí)現(xiàn)網(wǎng)站登陸功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08
JS簡(jiǎn)單實(shí)現(xiàn)禁止訪問某個(gè)頁面的方法
這篇文章主要介紹了JS簡(jiǎn)單實(shí)現(xiàn)禁止訪問某個(gè)頁面的方法,涉及基本的頁面跳轉(zhuǎn)操作技巧,需要的朋友可以參考下2016-09-09
基于BootStrap的前端分頁帶省略號(hào)和上下頁效果
這篇文章主要介紹了基于BootStrap的前端分頁帶省略號(hào)和上下頁效果,需要的朋友可以參考下2017-05-05
Javascript中判斷變量是數(shù)組還是對(duì)象(array還是object)
怎樣判斷一個(gè)JavaScript變量是array還是obiect,或許有很多初學(xué)者對(duì)此不是很清楚吧,下面為大家詳細(xì)解答下,希望對(duì)大家有所幫助2013-08-08
javascript實(shí)現(xiàn)簡(jiǎn)單小鋼琴有聲彈奏效果
用HTML5+javascript實(shí)現(xiàn)的小鋼琴,按下鋼琴鍵上的相應(yīng)字母用或用鼠標(biāo)點(diǎn)擊鋼琴鍵發(fā)聲,javascript代碼包含了對(duì)鼠標(biāo)按下、移動(dòng)和松開,以及鍵盤按下的事件監(jiān)聽2024-02-02

