小程序自定義彈框的方法
本文實(shí)例為大家分享了小程序自定義彈框的具體代碼,供大家參考,具體內(nèi)容如下
1、頁(yè)面簡(jiǎn)單布局
<button bindtap='ElasticFrameClick'>彈框</button> <view class="modal-mask" bindtap="hideModal" wx:if="{{showModal}}"></view> <view wx:if="{{showModal}}"> ? <view class="modal-content"> ? ? <view class='modal_title'>添加備注</view> ? ? <view class='modal_textarea'> ? ? ? <textarea placeholder='備注' maxlength='-1'></textarea> ? ? </view> ? ? <view class='btn'bindtap='hideModal'>保存</view> ? </view> </view>
2、樣式設(shè)置
/* 遮蓋層 */ ? .modal-mask { ? width: 100%; ? height: 100%; ? position: fixed; ? top: 0; ? left: 0; ? background: #000; ? opacity: 0.5; ? overflow: hidden; ? z-index: 9000; ? color: #fff; } ? /* 白色背景 */ ? .modal-content { ? position: fixed; ? top: 120rpx; ? left: 75rpx; ? z-index: 9500; ? width: 600rpx; ? height: 720rpx; ? overflow: hidden; ? background: #fff; ? border-radius: 20rpx; } ? .modal_title { ? height: 96rpx; ? width: 100%; ? line-height: 96rpx; ? border-top-right-radius: 20rpx; ? border-top-left-radius: 20rpx; ? background-color: #5a94ff; ? color: #fff; ? text-align: center; } ? .modal_textarea { ? height: 395rpx; ? width: calc(100% - 40rpx); ? margin: 20rpx; } ? .modal_textarea textarea { ? height: 100%; ? width: 100%; } ? .btn{ ? height: 70rpx; ? width: 390rpx; ? background-color: #5a94ff; ? color: #fff; ? text-align: center; ? line-height: 70rpx; ? border-radius: 50rpx; ? margin: 0 auto; ? margin-top: 40rpx; }
3、js控制
Page({ ? ? /** ? ?* 頁(yè)面的初始數(shù)據(jù) ? ?*/ ? data: { ? ? showModal: false, ? }, ? ? /** ? ?* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載 ? ?*/ ? onLoad: function(options) { ? ? }, ? ElasticFrameClick: function() { ? ? this.setData({ ? ? ? showModal: true ? ? }) ? }, ? ? toShowModal(e) { ? ? this.setData({ ? ? ? showModal: true ? ? }) ? }, ? ? // 隱藏彈框 ? hideModal() { ? ? this.setData({ ? ? ? showModal: false ? ? }); ? }, ? ? /** ? ?* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成 ? ?*/ ? onReady: function() { ? ? }, ? ? /** ? ?* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示 ? ?*/ ? onShow: function() { ? ? }, ? ? /** ? ?* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏 ? ?*/ ? onHide: function() { ? ? }, ? ? /** ? ?* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載 ? ?*/ ? onUnload: function() { ? ? }, ? ? /** ? ?* 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶下拉動(dòng)作 ? ?*/ ? onPullDownRefresh: function() { ? ? }, ? ? /** ? ?* 頁(yè)面上拉觸底事件的處理函數(shù) ? ?*/ ? onReachBottom: function() { ? ? }, ? ? /** ? ?* 用戶點(diǎn)擊右上角分享 ? ?*/ ? onShareAppMessage: function() { ? ? } })
4、頁(yè)面呈現(xiàn)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
有趣的JavaScript隱式類型轉(zhuǎn)換操作實(shí)例分析
這篇文章主要介紹了JavaScript隱式類型轉(zhuǎn)換操作,結(jié)合實(shí)例形式分析了JavaScript隱式類型轉(zhuǎn)換操作相關(guān)實(shí)現(xiàn)技巧與注意事項(xiàng),需要的朋友可以參考下2020-05-05javascript實(shí)現(xiàn)數(shù)組中的內(nèi)容隨機(jī)輸出
本文實(shí)例講述了javaScript數(shù)組隨機(jī)排列實(shí)現(xiàn)隨機(jī)洗牌功能的方法。分享給大家供大家參考。2015-08-08JavaScript高級(jí)程序設(shè)計(jì) 閱讀筆記(十四) js繼承機(jī)制的實(shí)現(xiàn)
繼承是面向?qū)ο笳Z(yǔ)言的必備特征,即一個(gè)類能夠重用另一個(gè)類的方法和屬性。在JavaScript中繼承方式的實(shí)現(xiàn)方式主要有以下五種:對(duì)象冒充、call()、apply()、原型鏈、混合方式2012-08-08fabric.js實(shí)現(xiàn)diy明信片功能
這篇文章主要為大家詳細(xì)介紹了fabric.js實(shí)現(xiàn)diy明信片功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-03-03javascript 實(shí)現(xiàn)文本使用省略號(hào)替代(超出固定高度的情況)
這篇文章主要介紹了javascript 實(shí)現(xiàn)文本使用省略號(hào)替代(超出固定高度的情況)的相關(guān)資料,需要的朋友可以參考下2017-02-02