小程序中可以自定義設(shè)置實(shí)現(xiàn)下拉菜單帶動(dòng)畫,下面是實(shí)現(xiàn)這種形式的方法:
在pick-header里添加篩選項(xiàng),在pick-container添加被篩選的選項(xiàng)內(nèi)容,content里顯示真正的內(nèi)容。
content的高度是會(huì)在js里根據(jù)當(dāng)前手機(jī)分辨率所動(dòng)態(tài)計(jì)算的,高度值為contentHeight,所以在里面可以嵌套一個(gè)scroll-view,設(shè)置高度為contentHeight即可實(shí)現(xiàn)內(nèi)容滑動(dòng)。
好了,廢話不多說,直接看圖附代碼。
下拉菜單示例.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') : ''}}" > 篩選項(xiàng) 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" > 我是內(nèi)容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; } /*篩選項(xiàng)容器布局*/ .pick-container { width : 100% ; height : 300 rpx; background-color : lightgoldenrodyellow; position : absolute ; z-index : 50 ; top : -228 rpx; } /*篩選項(xiàng)隱藏 顯示動(dòng)畫 start*/ @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 ; } /*篩選項(xiàng)隱藏 顯示動(dòng)畫 end*/ /*篩選項(xiàng)顯示出來的時(shí)候的陰影*/ .shadow { width : 100% ; background-color : rgba( 1 , 1 , 1 , 0.2 ); position : absolute ; z-index : 40 ; top : 72 rpx; } /*內(nèi)容容器布局*/ .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({ //動(dòng)態(tài)根據(jù)手機(jī)分辨率來計(jì)算內(nèi)容的高度(屏幕總高度-頂部篩選欄的高度) contentHeight: (res.windowHeight - 72 * res.screenWidth / 750) }); } }) }, onPickHeaderClick: function () { this .setData({ openPicker: ! this .data.openPicker, needAnimation : true }) }, }) |
以上就是實(shí)現(xiàn)微信小程序下拉菜單(帶動(dòng)畫)的方法實(shí)例的詳細(xì)內(nèi)容,希望可以幫助到到大家。
KESION 科汛軟件
KESION 科汛軟件是國(guó)內(nèi)領(lǐng)先的在線教育軟件及私域社交電商軟件服務(wù)提供商,長(zhǎng)期專注于為企業(yè)提供在線教育軟件及社交電商SaaS平臺(tái)解決方案。
公司核心產(chǎn)品云開店SaaS社交電商服務(wù)平臺(tái)、在線教育SaaS服務(wù)平臺(tái)、教育企業(yè)數(shù)字化SaaS云平臺(tái)、企微營(yíng)銷助手、私有化獨(dú)立部署品牌網(wǎng)校和在線教育咨詢等。KESION 不斷通過技術(shù)創(chuàng)新,提供產(chǎn)品和服務(wù),助力企業(yè)向數(shù)字化轉(zhuǎn)型,通過科技驅(qū)動(dòng)商業(yè)革新,讓商業(yè)變得更智慧!
科汛最新消息,蘑菇街自去年7月21日上線直播板塊,一個(gè)月內(nèi)人均播映次數(shù)已提升了40%,人均播映時(shí)長(zhǎng)提升了100%。順暢的邊看邊買體會(huì),明顯也給高轉(zhuǎn)化做出了貢獻(xiàn)。 蘑菇街的直播是...
小程序社交立減金功能實(shí)現(xiàn)了商家快速獲取社交、裂變傳播屬性。那么在經(jīng)營(yíng)小程序時(shí)如何開放社交立減金接口呢。...