您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇“小程序怎么自定义下拉动画”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“小程序怎么自定义下拉动画”文章吧。
小程序中可以自定义设置实现下拉菜单带动画,下面是实现这种形式的方法:
在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: 72rpx; z-index: 60; position: fixed; background-color: lightcoral;}/*筛选项容器布局*/.pick-container { width: 100%; height: 300rpx; background-color: lightgoldenrodyellow; position: absolute; z-index: 50; top: -228rpx;}/*筛选项隐藏 显示动画 start*/@keyframes slidown { from { transform: translateY(0%); } to { transform: translateY(100%); }}.slidown { display: block; animation: slidown 0.1s ease-in both;}@keyframes slidup { from { transform: translateY(100%); } to { transform: translateY(0%); }}.slidup { display: block; animation: slidup 0.2s ease-in both;}/*筛选项隐藏 显示动画 end*//*筛选项显示出来的时候的阴影*/.shadow { width: 100%; background-color: rgba(1, 1, 1, 0.2); position: absolute; z-index: 40; top: 72rpx;}/*内容容器布局*/.content { width: 100%; position: absolute; top: 72rpx; 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 }) },}) |
以上就是关于“小程序怎么自定义下拉动画”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。