微信小程序?qū)崿F(xiàn)select下拉框
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)select下拉框的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)代碼如下:
<view class="fenlei"> ? ? <!-- 下拉框 --> ? ? <view class="select_box"> ? ? ? <view class="select" catchtap="selectTaps"> ? ? ? ? <text class="select_text">{{selectDatas[indexs]}</text> ? ? ? ? <image class="select_img:{{shows&&'select_img_rotate'}}" ? ?src="../../../static/img/lifeCircle/arroundServe/xiala.png"></image> ? ? ? </view> ? ? ? <view class="option_box" style="height:{{shows?(selectDatas.length>8?890:selectDatas.length*110):0}}rpx;"> ? ? ? ? <text class="option-list" wx:for="{{selectDatas}}" wx:key="this" data-index="{{index}}" catchtap="optionTaps" ? ? ? ? ? style="{{indexs==selectDatas.length-1&&'border:0;'}}">{{item}}</text> ? ? ? </view> ? ? </view> </view>
css:
/* fenlei */ .fenlei{ ? margin: 0 25rpx; ? height: 80rpx; ? line-height: 80rpx; ? display: flex; ? align-items: center; ? background-color:#F5F6F7; } .fenlei text{ ? font-size: 30rpx; ? color: #999999; ? margin-left: 15rpx; } /* 下拉框 */ .select_box { ? width: 100%; ? text-align: left; ? position: relative; } .select { ? box-sizing: border-box; ? width: 100%; ? border-radius: 8rpx; ? display: flex; ? align-items: center; ? padding: 0 20rpx; } .select_text { ? font-size: 32rpx; ? flex: 1; ? color: #999999; } .select_img { ? width: 37rpx; ? height: 30rpx; ? display: block; ? transition: transform 0.3s; } .select_img_rotate { ? transform: rotate(180deg); } .option_box { ? position: absolute; ? width: 100%; ? box-sizing: border-box; ? border-top: 0; ? background: #fff; ? z-index: 100; ? text-align:center; ? transition: height 0.3s; ? overflow-y: auto; } .option-list { ? display: block; ? line-height: 106rpx; ? font-size: 32rpx; ? border-bottom: 1px solid #efefef; ? padding: 10rpx; ? color: rgb(102, 102, 102); ? cursor: pointer; }
js:
?/** ? ?* 頁(yè)面的初始數(shù)據(jù) ? ?*/ ? data: { ? ? shows: false, //控制下拉列表的顯示隱藏,false隱藏、true顯示 ? ? selectDatas: ['再生資源回收點(diǎn)', '家政服務(wù)點(diǎn)', '綜合超市','生鮮超市','郵政快遞綜合服務(wù)點(diǎn)','維修點(diǎn)','照相文印店','美容美發(fā)店'], //下拉列表的數(shù)據(jù) ? ? indexs: 0, //選擇的下拉列 表下標(biāo), ? }, // 點(diǎn)擊下拉顯示框 selectTaps(e) { ? console.log(e) ? this.setData({ ? ? shows: !this.data.shows, ? }); }, // 點(diǎn)擊下拉列表 optionTaps(e) { ? let Indexs = e.currentTarget.dataset.index; //獲取點(diǎn)擊的下拉列表的下標(biāo) ? console.log(Indexs) ? this.setData({ ? ? indexs: Indexs, ? ? shows: !this.data.shows ? }); },
注意:用catchtap,而不用bindtap的原因是為了阻止事件冒泡!
效果如下:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
微信小程序性能優(yōu)化之checkSession的使用
這篇文章主要介紹了微信小程序性能優(yōu)化之checkSession的使用,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2019-03-03JS和jQuery使用submit方法無(wú)法提交表單的原因分析及解決辦法
這篇文章主要介紹了JS和jQuery使用submit方法無(wú)法提交表單的原因分析及解決辦法的相關(guān)資料,需要的朋友可以參考下2016-05-05基于layer.js實(shí)現(xiàn)收貨地址彈框選擇然后返回相應(yīng)的地址信息
這篇文章主要介紹了基于layer.js實(shí)現(xiàn)收貨地址彈框選擇然后返回相應(yīng)的地址信息,需要的朋友可以參考下2017-05-05PHPMyAdmin導(dǎo)入時(shí)提示文件大小超出PHP限制的解決方法
這篇文章主要介紹了PHPMyAdmin導(dǎo)入時(shí)提示文件大小超出PHP限制的解決方法,造成這個(gè)問題的原因是PHP上傳大小限制為2MB,修改PHP.ini配置即可解決這問題,需要的朋友可以參考下2015-03-03uni-app多環(huán)境配置實(shí)現(xiàn)自動(dòng)部署的方式詳解
前后端分離開發(fā)模式中,無(wú)論前后端都有可能區(qū)分不同的環(huán)境配置,下面這篇文章主要給大家介紹了關(guān)于uni-app多環(huán)境配置實(shí)現(xiàn)自動(dòng)部署的相關(guān)資料,需要的朋友可以參考下2022-06-06JavaScript使用Promise控制并發(fā)請(qǐng)求
當(dāng)我們需要同時(shí)處理多個(gè)請(qǐng)求時(shí),如何避免請(qǐng)求之間的沖突和混亂呢,這就是今天我們要探討的話題——如何使用Promise控制并發(fā)請(qǐng)求,感興趣的可以了解一下2023-06-06