微信小程序 css3底部弹出框

日常记录:

goodsDetails.wxml


			<button class="button-green" bindtap="addCar" formType="submit">加入购物车</button>
			<button class="button-red" bindtap="immeBuy" formType="submit">立即购买</button>

	<view class="modals modals-bottom-dialog" hidden="{{hideModal}}">
		    <view class="modals-cancel" bindtap="hideModal"></view>
		    <view class="bottom-dialog-body bottom-pos" animation="{{animationData}}">
			<!--这里放内容-->
			</view> 
		</view>

goodsDetails.wxss


/*模态框*/
.modals{position:fixed; z-index: 999; top:0; left: 0; right:0; bottom: 0;}
.modals-cancel{position:absolute; z-index:1000; top:0; left: 0; right:0; bottom: 0; background-color: rgba(0,0,0,.5);}
.bottom-dialog-body{position:absolute; z-index:10001; bottom:0; left:0; right:0; padding:30rpx;  background-color: #fff;
border-radius: 50rpx 50rpx 0px 0px;
}
/*动画前初始位置*/
.bottom-pos{-webkit-transform:translateY(100%);transform:translateY(100%);}

 goodsDetails.js

Page({
	data: {
		hideModal:true, //模态框的状态  true-隐藏  false-显示
		animationData:{}

	},
	
	// 跳到购物车
	addCar() {
		this.showModal()
	},
	// 立即购买
	immeBuy() {
		this.showModal()
	},
	// 显示遮罩层
	  showModal: function () {
	  var that=this;
	  that.setData({
	    hideModal:false
	  })
	  var animation = wx.createAnimation({
	    duration: 600,//动画的持续时间 默认400ms   数值越大,动画越慢   数值越小,动画越快
	    timingFunction: 'ease',//动画的效果 默认值是linear
	  })
	  this.animation = animation 
	  setTimeout(function(){
	    that.fadeIn();//调用显示动画
	  },200)   
	},
	
	// 隐藏遮罩层
	hideModal: function () {
	  var that=this; 
	  var animation = wx.createAnimation({
	    duration: 800,//动画的持续时间 默认400ms   数值越大,动画越慢   数值越小,动画越快
	    timingFunction: 'ease',//动画的效果 默认值是linear
	  })
	  this.animation = animation
	  that.fadeDown();//调用隐藏动画   
	  setTimeout(function(){
	    that.setData({
	      hideModal:true
	    })      
	  },720)//先执行下滑动画,再隐藏模块
	  
	},
	
	//动画集
	fadeIn:function(){
	  this.animation.translateY(0).step()
	  this.setData({
	    animationData: this.animation.export()//动画实例的export方法导出动画数据传递给组件的animation属性
	  })    
	},
	fadeDown:function(){
	  this.animation.translateY(300).step()
	  this.setData({
	    animationData: this.animation.export(),  
	  })
	}, 
})

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值