欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

小程序自定義彈出框效果

 更新時間:2022年07月18日 16:15:00   作者:蔬菜_  
這篇文章主要為大家詳細介紹了小程序自定義彈出框效果,支持淡入淡出動畫,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了小程序自定義彈出框效果的具體代碼,供大家參考,具體內容如下

my-pop----api:

title ------字符串---------自定義彈窗標題
context ------字符串---------自定義彈窗內容
cancelTxt ------字符串---------取消按鈕文本
cancelCor ------字符串---------取消按鈕顏色
inp ------布爾值---------true文本彈出框---------fasle默認彈出框
okTxt ------字符串---------確定按鈕文字
okCor ------字符串---------確定按鈕顏色

@cancel ------事件---------點擊取消按鈕事件可攜帶value參數(shù)
@ok ------事件---------點擊確定按鈕事件可攜帶value參數(shù)

//使用方法
//在目標文件json文件里引入該組件
"usingComponents": {
? ? "mypop":"/components/my-pop"
?}

<mypop id="mypop" context="測試一下主體" inp="{{true}}" bindok="ok"/>
//給組件一個id?
this.selectComponent("#mypop").openPop(); ? //打開彈窗
ok(e) ?//點擊確定觸發(fā) 如果是inp類型彈窗 e 就是input的value , 反之e為空串
cancel(e) //點擊取消觸發(fā) ?如果是inp類型彈窗 e 就是input的value ?, 反之e為空串

彈窗js文件:

Component({
? /**
? ?* 組件的屬性列表
? ?*/
? properties: {
? ? title: {
? ? ? type: String,
? ? ? value: '默認標題',?
? ? },
? ? context: {
? ? ? type: String,
? ? ? value: '默認內容',?
? ? },
? ? inp:{
? ? ? type: Boolean,
? ? ? value: true
? ? },
? ? cancelTxt: {
? ? ? type: String,
? ? ? value: '取消',?
? ? },
? ? cancelCor:{
? ? ? type:String,
? ? ? value:'black'
? ? },
? ? okTxt: {
? ? ? type: String,
? ? ? value: '確認',?
? ? },
? ? okCor:{
? ? ? type:String,
? ? ? value:'red'
? ? },
? },

? /**
? ?* 組件的初始數(shù)據(jù)
? ?*/
? data: {
? ? show:false,
? ? animation:'',
? ? animationPop:'',
? ? inpVal:''
? },


? methods: {
? ? bindinput(e){
? ? ? let {value} = e.detail
? ? ? this.setData({inpVal:value})
? ? },
? ? ok(){
? ? ? this.triggerEvent("ok",this.data.inpVal);
? ? ? this.hidePop()
? ? ? this.setData({inpVal:''})
? ? },
? ? cancel(){
? ? ? this.triggerEvent("cancel",this.data.inpVal);
? ? ? this.hidePop()
? ? ? this.setData({inpVal:''})
? ? },
? ? openPop(){
? ? ? var animation = wx.createAnimation({
? ? ? ? ? duration: 200,
? ? ? ? ? timingFunction: "linear",
? ? ? ? ? delay: 0
? ? ? })
? ? ? this.animation = animation
? ? ? animation.opacity(0).step()
? ? ? this.setData({
? ? ? ? animationData: animation.export(),
? ? ? ? show:true
? ? ? })
? ? ? setTimeout(function () {
? ? ? ? ? animation.opacity(1).step()
? ? ? ? ? this.setData({
? ? ? ? ? ? ? animationData: animation.export()
? ? ? ? ? })
? ? ? }.bind(this), 200)
? ? },
? ? hidePop(){
? ? ? var animation = wx.createAnimation({
? ? ? ? ? duration: 200,
? ? ? ? ? timingFunction: "linear",
? ? ? ? ? delay: 0
? ? ? })
? ? ? this.animation = animation
? ? ? animation.opacity(0).step()
? ? ? this.setData({
? ? ? ? animationData: animation.export()
? ? ? })
? ? ? setTimeout(function () {
? ? ? ? ? this.setData({
? ? ? ? ? ? ? show:false
? ? ? ? ? })
? ? ? }.bind(this), 200)
? ? }
? }
})

彈窗wxml文件:

<!--components/my-pop.wxml-->
<view>
? <view class="mask" animation="{{animationData}}" bindtap="hidePop" wx:if="{{show}}">
? ? <view class="content" animation="{{animationPop}}" catchtap >
? ? ? <view class="title">{{title}}</view>
? ? ? <view class="txt" wx:if="{{!inp}}">{{context}}</view>
? ? ? <view class="inp" wx:if="{{inp}}">
? ? ? ? <input type="text" value='{{inpVal}}' bindinput="bindinput" name="" id="" />
? ? ? </view>
? ? ? <view class="btnView">
? ? ? ? <view class="cancel" hover-class="op5" bindtap="cancel" style="color:{{cancelCor}}">{{cancelTxt}}</view>
? ? ? ? <view class="partition"></view>
? ? ? ? <view class="ok" hover-class="op5" bindtap="ok" style="color:{{okCor}}">{{okTxt}}</view>
? ? ? </view>
? ? </view>
? </view>
</view>

彈窗wxss文件:

.mask{
? width: 100%;
? height: 100vh;
? position: fixed;
? top: 0; left: 0;
? z-index: 100;
? background: rgba(0, 0, 0, 0.4);
? display: flex;
? align-items: center;
? justify-content: center;
}
.content{
? background: #FFFFFF;
? border-radius: 16rpx;
? width: 70%;?
}
.title{
? padding: 32rpx 0rpx;
? text-align: center;
? font-weight: 500;
?? ?font-size: 32rpx;
?? ?color: black;
}
.txt{
? color: #000000;
? font-size: 24rpx;
? text-align: center;
? margin-bottom: 32rpx;
}
.btnView{
? border-top: 1rpx solid #D4D6D8;
? display: flex;
? align-items: center;
? justify-content: space-around;
}
.cancel{
? width: 49%;
? display: flex;
? align-items: center;
? justify-content: center;
? height: 80rpx; line-height: 80rpx;
}
.ok{
? width: 49%;
? display: flex;
? align-items: center;
? justify-content: center;
? height: 80rpx; line-height: 80rpx;
}
.inp{
? ? text-align: center;
? ? padding: 5px 0px;
?? ??? ?font-size: 24rpx;
?? ??? ?margin: auto;
?? ??? ?color: #868686;
?? ??? ?width: 90%;
?? ??? ?border: 1.2px solid #DEDEDE;
? ? border-radius: 5px;
? ? margin-bottom: 32rpx;
}
.op5{
? opacity: .5;
? background: rgba(0,0,0,0.05);
}
.partition{
? width: 2rpx;
? height: 80rpx;
? background: #D4D6D8;
}

彈窗json文件:

{
? "component": true,
? "usingComponents": {}
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 淺析js實現(xiàn)網(wǎng)頁截圖的兩種方式

    淺析js實現(xiàn)網(wǎng)頁截圖的兩種方式

    這篇文章主要介紹了淺析js實現(xiàn)網(wǎng)頁截圖的兩種方式,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-11-11
  • 詳解TypeScript中模塊化開發(fā)指南

    詳解TypeScript中模塊化開發(fā)指南

    在編程中,模塊是指將相關的代碼封裝在一起,形成一個獨立的單元,在這篇文章中,我們將深入探討在TypeScript中如何定義、導入和導出模塊,感興趣的可以了解一下
    2023-06-06
  • 詳解JavaScript中數(shù)組的reduce方法

    詳解JavaScript中數(shù)組的reduce方法

    js函數(shù)中有三個在特定場合很好用的函數(shù):reduce(),map(),filter()。而數(shù)組經(jīng)常用到的方法有push、join、indexOf、slice等等,但是有一個經(jīng)常被我們忽略的方法:reduce,這個方法簡直強大的不要不要的。下面通過這篇文章來一起學習學習吧。
    2016-12-12
  • Js遍歷鍵值對形式對象或Map形式的方法

    Js遍歷鍵值對形式對象或Map形式的方法

    下面小編就為大家?guī)硪黄狫s遍歷鍵值對形式對象或Map形式的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-08-08
  • js和jquery中獲取非行間樣式

    js和jquery中獲取非行間樣式

    本篇文章主要介紹了js和jquery中獲取非行間樣式的相關知識,具有很好的參考價值。下面跟著小編一起來看下吧
    2017-05-05
  • js實現(xiàn)漂亮的星空背景

    js實現(xiàn)漂亮的星空背景

    這篇文章主要為大家詳細介紹了js實現(xiàn)漂亮的星空背景,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • javascript函數(shù)的call、apply和bind的原理及作用詳解

    javascript函數(shù)的call、apply和bind的原理及作用詳解

    javascript函數(shù)的call、apply和bind?本質是用來實現(xiàn)繼承的,專業(yè)點說法就是改變函數(shù)體內部this的指向,當一個對象沒有某個功能時,就可以用這3個來從有相關功能的對象里借用過來,文中通過代碼示例介紹的非常詳細,需要的朋友可以參考下
    2023-05-05
  • JSON.stringify()方法講解

    JSON.stringify()方法講解

    今天小編就為大家分享一篇關于JSON.stringify()方法講解,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • iscroll實現(xiàn)下拉刷新功能

    iscroll實現(xiàn)下拉刷新功能

    這篇文章主要介紹了iscroll實現(xiàn)下拉刷新功能的相關代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Bootstrap與KnockoutJs相結合實現(xiàn)分頁效果實例詳解

    Bootstrap與KnockoutJs相結合實現(xiàn)分頁效果實例詳解

    KnockoutJS是一個JavaScript實現(xiàn)的MVVM框架。接下來通過本文給大家介紹Bootstrap與KnockoutJs相結合實現(xiàn)分頁效果,對bootstrap knockoutjs相關知識感興趣的朋友一起學習吧
    2016-05-05

最新評論