微信小程序?qū)崿F(xiàn)原生步驟條
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)原生步驟條的具體代碼,供大家參考,具體內(nèi)容如下
效果
(步驟條顏色不對(duì)是錄制工具的問(wèn)題)
思路
其實(shí)與輪播圖類似,使用了兩個(gè)并排的輪播容器,在滑動(dòng)監(jiān)聽(tīng)后,給圖片加上移動(dòng)和縮放動(dòng)畫(huà)。
擴(kuò)展
可以用于標(biāo)簽頁(yè)的切換。
vue與微信小程序有類似的地方,所以微信小程序做出的效果,原理也可用于vue在網(wǎng)頁(yè)上的應(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)文章
如何解決js函數(shù)防抖、節(jié)流出現(xiàn)的問(wèn)題
這篇文章主要介紹了如何解決js函數(shù)防抖、節(jié)流出現(xiàn)的問(wèn)題。SyntheticEvent對(duì)象是通過(guò)合并得到的。 這意味著在事件回調(diào)被調(diào)用后,SyntheticEvent 對(duì)象將被重用并且所有屬性都將被取消。 因此,您無(wú)法以異步方式訪問(wèn)該事件。,需要的朋友可以參考下2019-06-06IE不出現(xiàn)Flash激活框的小發(fā)現(xiàn)的js實(shí)現(xiàn)方法
IE不出現(xiàn)Flash激活框的小發(fā)現(xiàn)的js實(shí)現(xiàn)方法...2007-09-09簡(jiǎn)述JavaScript提交表單的方式 (Using JavaScript Submit Form)
這篇文章主要介紹了簡(jiǎn)述JavaScript提交表單的方式 (Using JavaScript Submit Form)的相關(guān)資料,需要的朋友可以參考下2016-03-03echarts柱狀圖坐標(biāo)軸內(nèi)容顯示不全的兩種解決辦法
本文主要介紹了echarts柱狀圖坐標(biāo)軸內(nèi)容顯示不全的兩種解決辦法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05JavaScript實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-12-12使用Javascript監(jiān)控前端相關(guān)數(shù)據(jù)的代碼
本篇文章詳細(xì)的介紹了使用Javascript監(jiān)控前端相關(guān)數(shù)據(jù),可以及時(shí)的監(jiān)控前端的錯(cuò)誤,加載時(shí)間等,有需要的可以了解一下。2016-10-10基于原生JavaScript實(shí)現(xiàn)SPA單頁(yè)應(yīng)用
單頁(yè)Web應(yīng)用?(single?page?web?application,SPA)?,就是只有一張Web頁(yè)面的應(yīng)用,是加載單個(gè)HTML?頁(yè)面并在用戶與應(yīng)用程序交互時(shí)動(dòng)態(tài)更新該頁(yè)面的Web應(yīng)用程序。本文將利用原生JS實(shí)現(xiàn)SPA單頁(yè)應(yīng)用,需要的可以參考一下2023-03-03