# tui-popup 弹层动画 会员组件

介绍

弹层动画,过渡效果。

# 引入

# uni-app引入

第一种,手动引入(可全局引入)

import tuiPopup from "@/components/thorui/tui-popup/tui-popup.vue"
export default {
	components:{
		tuiPopup
	}
}

第二种,开启easycom组件模式,如果不了解如何配置,可先查看 官网文档 (opens new window)

# uni-app版本平台差异说明

App-Nvue App-vue H5 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序

# 微信小程序引入(可在app.json中全局引入)

{
  "usingComponents": {
    "tui-popup": "/components/thorui/tui-popup/tui-popup"
  }
}

# 代码演示

部分功能演示,具体可参考示例程序以及文档API。

基础使用

通过 duration 属性设置动画过渡时间,modeClass 属性设置动画效果,styles 属性设置组件样式,show 属性设置弹层显示隐藏。

    <!--uni-app-->
    <tui-popup :duration="500" :modeClass="mode" :styles="styles" :show="transShow" @click="onTap" @change="change">
     <view class="tui-text">
     	<view>ThorUI文档地址:</view>
     	<view>https://thorui.cn/doc</view>
     </view>
    </tui-popup>
    
    // data 数据 及 方法
    export default {
     data() {
     	return {
     		show: false,
     		transShow: false,
     		mode: ['fade'],
     		styles: {}
     	}
     },
     methods: {
     	//调用此方法显示弹层
     	shown(mask) {
     		if (mask) {
     			this.$set(this.styles, 'backgroundColor', 'rgba(0,0,0,0.4)');
     		} else {
     			this.$set(this.styles, 'backgroundColor', 'rgba(0,0,0,0)');
     		}
     		setTimeout(() => {
     			this.transShow = !this.transShow;
     		}, 20);
     	},
     	onTap() {
     		this.transShow = false;
     		this.show = false;
     	},
     	change(e) {
     		console.log(e.detail);
     	}
     }
    }
    
    <!--微信小程序-->
    <tui-popup duration="{{500}}" modeClass="{{mode}}" styles="{{styles}}" show="{{transShow}}" bindclick="onTap" bindchange="change">
     <view class="tui-text">
     	<view>ThorUI文档地址:</view>
     	<view>https://thorui.cn/doc</view>
     </view>
    </tui-popup>
    
    // data 数据 及 方法
    Page({
      data: {
        show: false,
        transShow: false,
        mode: ['fade'],
        styles: {}
      },
      //调用此方法显示弹层
     shown(e) {
          let dataset=e.currentTarget.dataset
          let mask=dataset.mask
          let backgroundColor=`styles.backgroundColor`
          if (mask==1) {
            this.setData({
              [backgroundColor]:'rgba(0,0,0,0.4)'
            })
          } else {
            this.setData({
              [backgroundColor]:'rgba(0,0,0,0)'
            })
          }
          setTimeout(() => {
            this.setData({
              transShow:!this.data.transShow
            })
          }, 20);
       },
       onTap() {
          this.setData({
            transShow:false,
            show:false
          })
        },
        change(e) {
          console.log(e.detail.detail);
        }
    })
    
    // Make sure to add code blocks to your code group

    # Slots

    插槽名称 说明
    default 弹层内容,自定义展示

    # Props

    属性名 类型 说明 默认值
    show Boolean 控制弹层显示隐藏 false
    modeClass Array<String> 过渡动画类型:fade,slide-top,slide-right,slide-bottom,slide-left,zoom-in,zoom-out [ ]
    duration Number 动画过渡时间,单位ms 300
    styles Object 组件外层样式,同css样式 { ... }
    属性styles默认值
    {
    	position: 'fixed',
    	bottom: 0,
    	top: 0,
    	left: 0,
    	right: 0,
    	display: 'flex',
    	'justify-content': 'center',
    	'align-items': 'center'
    }
    

    # Events

    注:uni-app端绑定事件使用@前缀,如@click;微信小程序原生使用bind前缀,如bindclick

    事件名 说明 回调参数
    click popup弹层点击时触发 { detail : isShow 是否显示 }
    change 动画切换时触发 { detail : isShow 是否显示 }

    # 预览

    请以移动端效果为准,touch事件目前尚未在PC端做兼容。

    # 特别说明

    该组件为 会员组件,非开源内容,需开通会员才可获取使用。

    # 线上程序扫码预览

    ThorUI组件库 H5二维码 ThorUI示例
    ThorUI组件库小程序码 H5二维码 ThorUI示例小程序码
    Last Updated: 7/21/2023, 2:12:46 PM