電商項(xiàng)目中商品詳情頁,加入購物車或者下單時(shí)可以選擇商品屬性的彈出框,通過設(shè)置view的平移動(dòng)畫,達(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ū)υ捒虿]有顯示)
<!--屏幕背景變暗的背景 --> <view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></view> <!--彈出框 --> <view animation="{{animationData}}" class="commodity_attr_box" wx:if="{{showModalStatus}}">在這里寫彈出框里面的布局</view>4.設(shè)置點(diǎn)擊事件,給目標(biāo)view設(shè)置點(diǎn)擊函數(shù)showModal()或者h(yuǎn)ideModal()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注