1、wxml

1
2
3
4
5
6
7
8
<view>
<!--这是下拉框中的内容,即整个下拉框拉下来后的面板-->
<view class="drop-down-box {{status=='status01'?'status01':'status02'}}" style="display:{{display}}">

<!--一些自定义内容可在这里面进行填写-->

</view>
</view>

2、wxss

  • 这里我将下拉框面板,设置为从上往下拉,并且高度宽度是占满屏幕的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* 下拉框动画效果 */
@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、js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

Page({

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文件还是和上面的内容一样
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

Component({
/**
* 组件的属性列表
*/
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})
},
}
})