微信小程序实现一个简单的select下拉框,供大家参考,具体内容如下
用的是transform过渡,没用动画
看看效果
废话不多说,直接上代码
wxml:
1
2
3
4
5
6
7
8
9
10
11
12
|
< view class = "item" > < label class = "first" >< text >*</ text >公司/商户类型:</ label > <!-- 通过点击事件改变图片的旋转角度、自定义下拉框的高度 --> < view class = "value" bindtap = "select" > < view style = "display:inline-block;" >{{type!=''?type:'选择商户类型'}}</ view > < image src = "../img/sj@2x.png" class = "sanjiao" style = "{{isSelect?'transform:rotateZ(180deg)':''}}" /> <!-- select --> < view class = "select" style = "{{isSelect?'height:'+54*types.length+'rpx;':'border:0'}}" > < view class = "type" catchtap = "getType" wx:for = "{{types}}" data-type = "{{item}}" wx:key = "type" >{{item}}</ view > </ view > </ 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
|
.sanjiao{ width : 18 rpx; height : 10 rpx; margin-left : 20 rpx; transition: 0.5 s; /* 选转图片过渡 */ } .select{ position : absolute ; z-index : 10 ; border : 2 rpx solid #aaaaaa ; padding : 0 8 rpx; top : 46 rpx; left : -10 rpx; width : 210 rpx; overflow : auto ; height : 0 ; max-height : 200 rpx; background-color : #fff ; box-sizing: border-box; transition: height 0.5 s; /* 高度变换过渡 */ } .select .type{ color : #aaaaaa ; border-top : 2px solid #dadada ; padding : 6 rpx; } .select :first-child{ border : 0 ; } |
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
data: { isSelect: false , //展示类型? types:[ '类型一' , '类型二' ], //公司/商户类型 type: "" , //公司/商户类型 }, //点击控制下拉框的展示、隐藏 select: function (){ var isSelect = this .data.isSelect this .setData({ isSelect:!isSelect}) }, //点击下拉框选项,选中并隐藏下拉框 getType: function (e){ let value = e.currentTarget.dataset.type this .setData({ type:value , isSelect: false , }) }, |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/zk_csdn917/article/details/109816223