微信小程序商品詳情頁底部彈出框
電商項目中商品詳情頁,加入購物車或者下單時可以選擇商品屬性的彈出框,通過設置view的平移動畫,達到從底部彈出的樣式
1.js代碼(一般情況下只調(diào)用顯示對話框的函數(shù),當點擊對話框外部的時候,對話框可以消失)
//顯示對話框 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) }, //隱藏對話框 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; } /*對話框 */ .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對象中初始化,初始化為false,因為最初的時候?qū)υ捒虿]有顯示)
<!--屏幕背景變暗的背景 --> <view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></view> <!--彈出框 --> <view animation="{{animationData}}" class="commodity_attr_box" wx:if="{{showModalStatus}}">在這里寫彈出框里面的布局</view>
4.設置點擊事件,給目標view設置點擊函數(shù)showModal()或者hideModal()
為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript讓setInteval里的函數(shù)參數(shù)中的this指向特定的對象
話說阿里巴巴今年的校園招聘有一道題目考了一個知識點,那就是setInterval的參數(shù)函數(shù)里的this指向.2010-01-01強悍無比的WEB開發(fā)好助手FireBug(Firefox Plugin)
強悍無比的WEB開發(fā)好助手FireBug(Firefox Plugin)...2007-01-01bootstrap和jQuery.Gantt的css沖突 如何解決
這篇文章主要介紹了bootstrap和jQuery.Gantt的css沖突,本文給出了解決沖突的解決方法,感興趣的小伙伴們可以參考一下2016-05-05js實現(xiàn)帶關(guān)閉按鈕始終顯示在網(wǎng)頁最底部工具條的方法
這篇文章主要介紹了js實現(xiàn)帶關(guān)閉按鈕始終顯示在網(wǎng)頁最底部工具條的方法,是非常實用的javascript固定效果,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03