欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序?qū)崿F(xiàn)列表左右滑動(dòng)

 更新時(shí)間:2020年11月19日 10:24:45   作者:小北1943  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)列表左右滑動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

做微信小程序開發(fā),和app一樣經(jīng)常會(huì)用到列表左右滑動(dòng)操作(刪除等),目前微信小程序官方?jīng)]有提供相應(yīng)的控件。

只能我們自己來做,方法很多,我這里給個(gè)思路,僅供參考,歡迎討論。

1、我們可以把列表的元素放在scroll-view控件中,并且讓scroll-view實(shí)現(xiàn)橫向滑動(dòng)

2、把列表內(nèi)容項(xiàng)的寬度占滿手機(jī)寬度,利用rpx特性(自適應(yīng)屏幕),默認(rèn)iphon6就是750rpx,只要設(shè)置大于等于750rpx就可以。

3、監(jiān)聽滑動(dòng)后列表操作事件,即可

細(xì)節(jié)點(diǎn):

(1)scroll-view實(shí)現(xiàn)橫向滑動(dòng),這個(gè)微信文檔寫的不是很詳細(xì)

第一步,wxml中在scroll-view控件中,寫上 scroll-x

<scroll-view scroll-x class='scroll-container'>
</scroll-view>

第二步,要在wxss樣式文件中增加上white-space: nowrap;

.scroll-container{
height: 200rpx;
background-color: floralwhite;
margin-top: 20rpx;
display: flex;
flex-direction: row;
align-items: center;
white-space: nowrap;
width: 100%;}

第三步:scroll-view 默認(rèn)滑動(dòng)的時(shí)候,是有個(gè)線條的。體驗(yàn)不好,去掉。大家可以對(duì)比下效果

::-webkit-scrollbar{ width: 0; height: 0; color: transparent;} 

(2)比如滑動(dòng)刪除第一條數(shù)據(jù)后,第二條數(shù)據(jù)的默認(rèn)是處于滑動(dòng)后狀態(tài),把操作項(xiàng)都顯示出來了,建議每次操作完,把scroll-view的位置復(fù)原。修改scroll-left的值就好,我每次操作完,就把該值設(shè)置為0。

<scroll-view scroll-x class='scroll-container' scroll-left='{{scroll_left}}'

(3)列表內(nèi)容可能會(huì)超出屏幕默認(rèn)值,我這個(gè)例子是單行顯示的,所有只要文字大于一定數(shù)量就截取。單獨(dú)寫了個(gè)函數(shù)把數(shù)據(jù)處理了下,這個(gè)可以實(shí)際情況實(shí)際處理。

代碼如下:

wxml:注意class done1是為了做完成后效果,這里只是演示就簡(jiǎn)單實(shí)現(xiàn)了下,實(shí)際應(yīng)該針對(duì)對(duì)應(yīng)的列表進(jìn)行處理,可以考慮把原數(shù)據(jù)做成數(shù)組字典。 /data-content 是為了刪除的時(shí)候,知道是刪除了哪一行/

<view>
 <block wx:for='{{items}}' wx:key=''>
 <scroll-view scroll-x class='scroll-container' scroll-left='{{scroll_left}}'>
  <text class='content {{done1}}'>{{item}}</text>
  <text class='del' data-content='{{index}}' bindtap='del'>刪除</text>
  <text class='done' data-content='{{index}}' bindtap='done'>完成</text>
 </scroll-view>
 </block>
</view>

wxss:

::-webkit-scrollbar{

 width: 0;
 height: 0;
 color: transparent;

}

.scroll-container{

 height: 200rpx;
 background-color: floralwhite;
 margin-top: 20rpx;
 display: flex;
 flex-direction: row;
 align-items: center;
 white-space: nowrap;
 width: 100%;

}

.content{

 padding-left: 20rpx;
 display: inline-block;
 line-height: 200rpx;
 font-size: 40rpx;
 width: 750rpx;

}

.del{

 display: inline-flex;
 width: 200rpx;
 height: 200rpx;
 line-height: 200rpx;
 align-items: center;
 justify-content: center;
 background-color: red;
 color: white;

}

.done{
 display: inline-flex;
 width: 200rpx;
 height: 200rpx;
 line-height: 200rpx;
 align-items: center;
 justify-content: center;
 background-color: green;
 color: white;
}
.done1{
 text-decoration: line-through;
 color: gainsboro;
}

js:

// pages/test06/test06.js
//hhString是為了處理下列表內(nèi)容的,超出了就是用...顯示,可以注釋掉不用
import {hhString} from '../../utils/util.js';
Page({

 /**

 * 頁(yè)面的初始數(shù)據(jù)

 */

 data: {

 items: ['我是第一條測(cè)試數(shù)據(jù)', '我是第二條測(cè)試數(shù)據(jù)', '我是第三條測(cè)試數(shù)據(jù) ', '我是第四條測(cè)試數(shù)據(jù)', '我是第五條測(cè)試數(shù)據(jù) ', '我是第六條測(cè)試數(shù)據(jù),數(shù)據(jù)很多很多很多很多很多', '我是第七條測(cè)試數(shù)據(jù)', '我是第八條測(cè)試數(shù)據(jù)', '我是第九條測(cè)試數(shù)據(jù)'],

 scroll_left:'0rpx',

 },

 /**
 * 生命周期函數(shù)--監(jiān)聽頁(yè)面加載
 */

 onLoad: function (options) {
 //hhString是為了處理下列表內(nèi)容的,超出了就是用...顯示,可以注釋掉不用

 this.setData({

  items:hhString(this.data.items)

 })

 },

 del:function(event){

 //event.currentTarget.dataset.content獲取到列表的所在的行號(hào)
 //splice 刪除數(shù)組數(shù)據(jù)函數(shù),第一個(gè)參數(shù)是位置,第二個(gè)是個(gè)數(shù)

 this.data.items.splice(event.currentTarget.dataset.content,1);
 this.setData({
  items: this.data.items,
  scroll_left:'0rpx'

 });

 },

 done: function (event) {
 //這里簡(jiǎn)易實(shí)現(xiàn)了下效果,沒有針對(duì)對(duì)應(yīng)的行號(hào),實(shí)際業(yè)務(wù)再修改
 this.setData({
  scroll_left: '0rpx',
  done1: 'done1'

 });

 },

})

util->util.js

const hhString = (data)=>{
 let hstring = [];
 for(let val of data){
 if(val.length>10){
  val = val.substring(0,10);
  val = val+'...'

 }
 hstring.push(val);

 }
 return hstring;

}

module.exports = {
 hhString:hhString

}

為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論