微信小程序商品詳情頁(yè)的底部彈出框效果
電商項(xiàng)目中商品詳情頁(yè),加入購(gòu)物車或者下單時(shí)可以選擇商品屬性的彈出框,通過(guò)設(shè)置view的平移動(dòng)畫(huà),達(dá)到從底部彈出的樣式
1.js代碼(一般情況下只調(diào)用顯示對(duì)話框的函數(shù),當(dāng)點(diǎn)擊對(duì)話框外部的時(shí)候,對(duì)話框可以消失)
//顯示對(duì)話框
showModal: function () {
// 顯示遮罩層
var animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
delay: 0
})
this.animation = animation
animation.translateY(300).step()
this.setData({
animationData: animation.export(),
showModalStatus: true
})
setTimeout(function () {
animation.translateY(0).step()
this.setData({
animationData: animation.export()
})
}.bind(this), 200)
},
//隱藏對(duì)話框
hideModal: function () {
// 隱藏遮罩層
var animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
delay: 0
})
this.animation = animation
animation.translateY(300).step()
this.setData({
animationData: animation.export(),
})
setTimeout(function () {
animation.translateY(0).step()
this.setData({
animationData: animation.export(),
showModalStatus: false
})
}.bind(this), 200)
}
2.wxss代碼
/*使屏幕變暗 */
.commodity_screen {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
background: #000;
opacity: 0.2;
overflow: hidden;
z-index: 1000;
color: #fff;
}
/*對(duì)話框 */
.commodity_attr_box {
height: 300rpx;
width: 100%;
overflow: hidden;
position: fixed;
bottom: 0;
left: 0;
z-index: 2000;
background: #fff;
padding-top: 20rpx;
}
3.wxml代碼 (其中的showModalStatus變量要現(xiàn)在js代碼中的data對(duì)象中初始化,初始化為false,因?yàn)樽畛醯臅r(shí)候?qū)υ捒虿](méi)有顯示)
<!--屏幕背景變暗的背景 -->
<view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></view>
<!--彈出框 -->
<view animation="{{animationData}}" class="commodity_attr_box" wx:if="{{showModalStatus}}">在這里寫(xiě)彈出框里面的布局</view>
4.設(shè)置點(diǎn)擊事件,給目標(biāo)view設(shè)置點(diǎn)擊函數(shù)showModal()或者h(yuǎn)ideModal()
為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開(kāi)發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解JavaScript基于面向?qū)ο笾畡?chuàng)建對(duì)象(1)
這篇文章主要介紹了JavaScript基于面向?qū)ο笾畡?chuàng)建對(duì)象,對(duì)創(chuàng)建對(duì)象進(jìn)行了詳細(xì)描述,感興趣的小伙伴們可以參考一下2015-12-12
js 數(shù)組 find,some,filter,reduce區(qū)別詳解
區(qū)分清楚Array中filter、find、some、reduce這幾個(gè)方法的區(qū)別,根據(jù)它們的使用場(chǎng)景更好的應(yīng)用在日常編碼中。具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06
JS實(shí)現(xiàn)勻加速與勻減速運(yùn)動(dòng)的方法示例
這篇文章主要介紹了JS實(shí)現(xiàn)勻加速與勻減速運(yùn)動(dòng)的方法,涉及javascript結(jié)合時(shí)間函數(shù)與數(shù)學(xué)運(yùn)算動(dòng)態(tài)操作頁(yè)面元素樣式的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-09-09
微信小程序中target和currentTarget的區(qū)別小結(jié)
這篇文章主要給大家介紹了關(guān)于微信小程序中target和currentTarget區(qū)別的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
JavaScript中函數(shù)(Function)的apply與call理解
這篇文章主要介紹了JavaScript中函數(shù)(Function)的apply與call理解,本文講解了JavaScript函數(shù)調(diào)用分為4中模式以及通過(guò)apply和call實(shí)現(xiàn)擴(kuò)展和繼承兩方面,需要的朋友可以參考下2015-07-07
基于Bootstrap+jQuery.validate實(shí)現(xiàn)表單驗(yàn)證
這篇文章主要為大家詳細(xì)介紹了基于Bootstrap+jQuery.validate實(shí)現(xiàn)表單驗(yàn)證,感興趣的小伙伴們可以參考一下2016-05-05

