这篇“小程序怎么自定义下拉动画”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“小程序怎么自定义下拉动画”文章吧。
小程序中可以自定义设置实现下拉菜单带动画,下面是实现这种形式的方法:
在pick-header里添加筛选项,在pick-container添加被筛选的选项内容,content里显示真正的内容。
content的高度是会在js里根据当前手机分辨率所动态计算的,高度值为contentHeight,所以在里面可以嵌套一个scroll-view,设置高度为contentHeight即可实现内容滑动。
下拉菜单示例.gif
wxml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | < view class = "content-container" >
< view class = "pick-header" bindtap = "onPickHeaderClick" >
筛选pick-header view z-index:60
</ view >
< view class = "pick-container {{needAnimation ? (openPicker ? 'slidown' : 'slidup') : ''}}" >
筛选项 pick-container view z-index:50
</ view >
< view class = "shadow" style = "height:{{contentHeight}}px;line-height:{{contentHeight}}px" hidden = " {{!openPicker}}" >我是半透明阴影遮罩 view shadow z-index:40</ view >
< view class = "content" style = "height:{{contentHeight}}px" >
我是内容content view z-index:20
</ view >
</ view >
|
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 | .content-container {
width : 100% ;
position : absolute ;
}
.pick-header {
width : 100% ;
height : 72 rpx;
z-index : 60 ;
position : fixed ;
background-color : lightcoral;
}
.pick-container {
width : 100% ;
height : 300 rpx;
background-color : lightgoldenrodyellow;
position : absolute ;
z-index : 50 ;
top : -228 rpx;
}
@keyframes slidown {
from {
transform: translateY( 0% );
}
to {
transform: translateY( 100% );
}
}
.slidown {
display : block ;
animation: slidown 0.1 s ease-in both ;
}
@keyframes slidup {
from {
transform: translateY( 100% );
}
to {
transform: translateY( 0% );
}
}
.slidup {
display : block ;
animation: slidup 0.2 s ease-in both ;
}
.shadow {
width : 100% ;
background-color : rgba( 1 , 1 , 1 , 0.2 );
position : absolute ;
z-index : 40 ;
top : 72 rpx;
}
.content {
width : 100% ;
position : absolute ;
top : 72 rpx;
z-index : 20 ;
}
|
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
28
29
30 | Page({
data: {
openPicker: false ,
needAnimation : false ,
contentHeight: 0
},
onLoad: function () {
},
onReady: function () {
var that = this ;
wx.getSystemInfo({
success: function (res) {
that.setData({
contentHeight: (res.windowHeight - 72 * res.screenWidth / 750)
});
}
})
},
onPickHeaderClick: function () {
this .setData({
openPicker: ! this .data.openPicker,
needAnimation : true
})
},
})
|
以上就是关于“小程序怎么自定义下拉动画”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注天达云行业资讯频道。