您好,登錄后才能下訂單哦!
微信小程序 slider的簡單實例
實現效果圖:
微信小程序slider應用,可加減的slider控制
<view class="control-w "> <block wx:for="{{controls}}" wx:key="id" wx:for-item="v"> <view class="slide-item"> <view class="itemName">{{v.name}}</view> <view class="slidewrap"> <text class="s-con" data-id="{{v.id}}" bindtap="minusCount">-</text> <slider class="slide" bindchange="sliderchange" step="10" value="{{v.value}}" data-id="{{v.id}}" max="{{v.max}}" min="0" wx:if="{{index<3}}" /> <slider class="slide" bindchange="sliderchange" step="10" value="{{v.value}}" data-id="{{v.id}}" max="{{v.max}}" min="0" wx:if="{{index==3}}" /> <text class="s-con" data-id="{{v.id}}" data-max="{{v.max}}" bindtap="addCount">+</text> </view> </view> </block> </view>
頁面結構
Page({ data: { controls: [ { id: 1, name: '功能一', value: 30, max: 60 }, { id: 2, name: '功能二', value: 30, max: 60 }, { id: 3, name: '功能三', value: 30, max: 60 }, { id: 4, name: '功能四', value: 50, max: 100 } ] }, // 控制加 addCount: function (event) { let data = event.currentTarget.dataset let controls = this.data.controls let control = controls.find(function (v) { return v.id == data.id }) let control1 = controls.find(function (v) { return v.max == data.max }) if (control.value > control1.max) return control.value += 10; this.setData({ 'controls': controls }) }, // 控制減 minusCount: function (event) { let data = event.currentTarget.dataset let controls = this.data.controls let control = controls.find(function (v) { return v.id == data.id }) if (control.value <= 0) return control.value -= 10; this.setData({ 'controls': controls }) }, //拖動 sliderchange: function (e) { let data = e.currentTarget.dataset let controls = this.data.controls let control = controls.find(function (v) { return v.id == data.id }) this.setData({ 'controls': controls }) } })
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。