本文主要和大家分享微信小程序模拟下拉菜单开发实例,希望能帮助到大家。
一.知识点
1.实现动态显示和隐藏某个控件
列表1
1 2 3 4 5 6 7 8 | data:{
open:false
},
showitem: function (){
this.setData({
open:!this.data.open
})
},
|
1 2 3 4 5 6 | .display_show{
display: block;
}
.display_none{
display: none;
}
|
2.通过 data-* 和 e.target.dateset 传递参数
{{firstPerson}}
吃
1 2 3 | this.setData({
firstPerson:e.target.dataset.me,
})
|
这时:firstPerson=吃
3.弹性盒字:display:flex;
1 2 3 4 | <view class = "phone_one" bindtap= "clickPerson" >
<view class = "phone_personal" >{{firstPerson}}</view>
<image src= "../../image/i.png" class = "personal_image {{selectArea ? 'rotateRight' :''}}" ></image>
</view>
|
在父级:
display:flex;
justify-content:space-between;
这样子集就会并列。justify-content:space-between;这样子集就会分别在在俩头
二.事列
(1).下拉列表
1.wxml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <view class = "page" >
<view class = "page_bd" >
<view class = "body_head" bindtap= "showitem" >点击我显示下拉列表</view>
<navigator url= "pages/list/list" >
<view class = "{{open?'display_show':'display_none'}}" >列表1</view>
</navigator>
<navigator url= "pages/scroll-view/index" >
<view class = "{{open?'display_show':'display_none'}}" >列表2</view>
</navigator>
<navigator url= "pages/scroll-view/index" >
<view class = "{{open?'display_show':'display_none'}}" >列表3</view>
</navigator>
</view>
</view>
|
2.wxss
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | .page_bd{
padding: 10px;
background-color: snow;
}
.body_head{
border: 1px solid;
border-color: beige;
padding: 10px;
}
.display_show{
display: block;
border: 1px solid;
border-color: beige;
padding: 10px;
}
.display_none{
display: none;
}
|
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 | Page({
data:{
open:false
},
showitem: function (){
this.setData({
open:!this.data.open
})
},
onLoad: function (options){
},
onReady: function (){
},
onShow: function (){
},
onHide: function (){
},
onUnload: function (){
}
})
|
(2).下拉菜单
1.wxml
1 2 3 4 5 6 7 8 9 10 11 | <view class = "phone_one" bindtap= "clickPerson" >
<view class = "phone_personal" >{{firstPerson}}</view>
<image src= "../../image/i.png" class = "personal_image {{selectArea ? 'rotateRight' :''}}" ></image>
</view>
<view class = "person_box" >
<view class = "phone_select" hidden= "{{selectPerson}}" >
<view class = "select_one" bindtap= "mySelect" data-me= "吃" >吃</view>
<view class = "select_one" bindtap= "mySelect" data-me= "喝" >喝</view>
<view class = "select_one" bindtap= "mySelect" data-me= "玩" >玩</view>
</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 | phone_personal{
width: 100%;
color:rgb(34, 154, 181);
height:100rpx;
line-height:100rpx;
text-align: center;
}
.phone_one{
display:flex;
position:relative;
justify-content:space-between;
background-color:rgb(239, 239, 239);
width:90%;
height:100rpx;
margin:22px auto;
border-radius:10rpx;
border-bottom:2rpx solid rgb(255, 255, 255);
line-height:51px;
padding-left:10px;
}
.person_box{
position: relative;
}
.phone_select{
margin-top:0;
z-index: 100;
position: absolute;
}
.select_one{
text-align: center;
background-color:rgb(239, 239, 239);
width:676rpx;
height:100rpx;
line-height:100rpx;
margin:0 5%;
border-bottom:2rpx solid rgb(255, 255, 255);
}
.personal_image{
z-index: 100;
position: absolute;
right:2.5%;
width: 34rpx;
height: 20rpx;
margin:40rpx 20rpx 40rpx 0;
transition: All 0.4s ease;
-webkit-transition: All 0.4s ease;
}
.rotateRight{
transform: rotate(180deg);
}
|
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | Page({
data:{
selectPerson:true,
firstPerson:'兴趣',
selectArea:false,
},
clickPerson: function (){
var selectPerson = this.data.selectPerson;
if (selectPerson == true){
this.setData({
selectArea:true,
selectPerson:false,
})
} else {
this.setData({
selectArea:false,
selectPerson:true,
})
}
} ,
mySelect: function (e){
this.setData({
firstPerson:e.target.dataset.me,
selectPerson:true,
selectArea:false,
})
},
onLoad: function (options){
},
onReady: function (){
},
onShow: function (){
},
onHide: function (){
},
onUnload: function (){
}
})
|
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~