微信小程序之animation底部弹窗动画(两种方法) |
您所在的位置:网站首页 › animate背景设置 › 微信小程序之animation底部弹窗动画(两种方法) |
简单分享一下常用的底部弹窗层或下拉框弹出层(代码需要修改)的内容弹窗的动画效果,这里分享的是点击按钮后底部弹窗的动画效果。第一种方式是动态设置显示区域的高度,第二种方法是动态设置显示区域的移动的位置(使用到transform:translateY); (一)实现效果1、wxml代码: 点击底部动画弹窗 测试一下 复制代码2、wxss代码: .pupContentBG { width: 100vw; height: 100vh; position: fixed; top: 0; } .pupContent { width: 100%; background: pink; position: absolute; bottom: 0; box-shadow: 0 0 10rpx #333; height: 0; z-index: 999; } /* 设置显示的背景 */ .showBG { display: block; } .hideBG { display: none; } /* 弹出或关闭动画来动态设置内容高度 */ @keyframes slideBGtUp { from { background: transparent; } to { background: rgba(0, 0, 0, 0.1); } } @keyframes slideBGDown { from { background: rgba(0, 0, 0, 0.1); } to { background: transparent; } } /* 显示或关闭内容时动画 */ .openBG { animation: slideBGtUp 0.5s ease-in both; /* animation-fill-mode: both 动画将会执行 forwards 和 backwards 执行的动作。 */ } .closeBG { animation: slideBGDown 0.5s ease-in both; /* animation-fill-mode: both 动画将会执行 forwards 和 backwards 执行的动作。 */ } /* 设置显示内容 */ .showContent { display: block; } .hideContent { display: none; } /* 弹出或关闭动画来动态设置内容高度 */ @keyframes slideContentUp { from { height: 0; } to { height: 800rpx; } } @keyframes slideContentDown { from { height: 800rpx; } to { height: 0; } } /* 显示或关闭内容时动画 */ .open { animation: slideContentUp 0.5s ease-in both; /* animation-fill-mode: both 动画将会执行 forwards 和 backwards 执行的动作。 */ } .close { animation: slideContentDown 0.5s ease-in both; /* animation-fill-mode: both 动画将会执行 forwards 和 backwards 执行的动作。 */ } 复制代码3、js代码: data: { click: false, //是否显示弹窗内容 option: false, //显示弹窗或关闭弹窗的操作动画 }, // 用户点击显示弹窗 clickPup: function() { let _that = this; if (!_that.data.click) { _that.setData({ click: true, }) } if (_that.data.option) { _that.setData({ option: false, }) // 关闭显示弹窗动画的内容,不设置的话会出现:点击任何地方都会出现弹窗,就不是指定位置点击出现弹窗了 setTimeout(() => { _that.setData({ click: false, }) }, 500) } else { _that.setData({ option: true }) } }, 复制代码第二种动态平移内容区域位置方法实现:相对于第一种代码修改的部分:只修改的了粉红色区域的高度和粉红色区域弹出和收回的动画效果: /* 弹出或关闭动画来动态设置内容高度 */ @keyframes slideContentUp { from { transform: translateY(100%); /*设置为正数则底部弹出来,负数则相反*/ } to { transform: translateY(0%); } } @keyframes slideContentDown { from { transform: translateY(0%); } to { transform: translateY(100%); } } 复制代码参考资料: CSS3(三)Animation 入门详解 微信小程序CSS3动画下拉菜单感谢阅读。 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |