1、wxml12345678<view> <!--这是下拉框中的内容,即整个下拉框拉下来后的面板--> <view class="drop-down-box {{status=='status01'?'status01':'status02'}}" style="display:{{display}}"> <!--一些自定义内容可在这里面进行填写--> </view></view> 2、wxss 这里我将下拉框面板,设置为从上往下拉,并且高度宽度是占满屏幕的 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778/* 下拉框动画效果 */@keyframes kf_first { from { transform: translateY(-900rpx); } to { transform: translateY(0rpx); }} @keyframes kf_last { from { transform: translateY(0rpx); } to { transform: translateY(-2000rpx); }}.drop-down-box{ display: flex; flex-direction: column; background-color: #ededed;}.status01{ animation: kf_first; /* keyframe first */ animation-duration: 0.5s; animation-iteration-count: 1; animation-fill-mode: forwards; /* width: 750rpx; height: 860rpx; */ width: 100%; height: 100%; border: 2rpx solid #ededed; /* position: absolute; */ position: fixed; /* top: 0; */ bottom: 0; left: 0; z-index: 1454; background-color: #fff; overflow: scroll;}.status02{ animation: kf_last; /* keyframe last */ animation-duration: 1s; animation-iteration-count: 1; animation-fill-mode: forwards; /* width: 750rpx; height: 860rpx; */ width: 100%; height: 100%; border: 2rpx solid #ededed; /* position: absolute; */ position: fixed; /* top: 0; */ bottom: 0; left: 0; z-index: 1454; background-color: #fff; overflow: scroll;}/*我这里有占满屏幕,如果不是占满屏幕,其中有漏出一些其他内容,但要覆盖除了下拉框外的其他内容,可使用这个mask面罩 */.mask{ position: fixed; width: 100%; height: 100%; top: 0px; background: rgba(0, 0, 0, 0.4); overflow: hidden;} 3、js123456789101112131415161718192021222324252627Page({ data: { // 初始化下拉框相关参数 display: "none", status: "status01", areHidden: true, }, // 下拉框相关函数: //显示下拉框 appear: function(){ this.setData({display: 'block'}) this.setData({status: 'status01'}) this.setData({areHidden: false}) }, //隐藏下拉框 disappear: function(){ this.setData({status: 'status02'}) this.setData({areHidden: true}) }, }) 4、封装成组件 .wxml文件还是和上面的内容一样 .wxss文件还是和上面的内容一样 123456789101112131415161718192021222324252627282930Component({ /** * 组件的属性列表 */ properties: { }, data: { //初始化下拉框相关参数 display: "none", status: "status01", areHidden: true, }, methods: { //显示下拉框 appear: function(){ this.setData({display: 'block'}) this.setData({status: 'status01'}) this.setData({areHidden: false}) }, //隐藏下拉框 disappear: function(){ this.setData({status: 'status02'}) this.setData({areHidden: true}) }, }}) Author: BinGCULink: http://bingcu.com/2020/07/18/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E4%B9%8B%E5%A6%82%E4%BD%95%E7%BC%96%E5%86%99%E4%B8%8B%E6%8B%89%E6%A1%86/Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.微信小程序 Donate微信支付寶Previous PostShell脚本自动化管理博客部署与备份Next PostPE(Portable Executable) 思维导图 Comment