您好,登錄后才能下訂單哦!
這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)怎么在微信小程序中實(shí)現(xiàn)一個(gè)多行文字滾動(dòng)效果,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
具體內(nèi)容如下
wxml
<view class="full" > <swiper autoplay="true" interval="3000" duration="500" circular="true" vertical="true" > <swiper-item wx:for="{{topnewslist}}" wx:key="{{index}}" catchtouchmove='catchTouchMove'> <van-notice-bar scrollable="{{false}}" bindtap="tonewsdetail" wx:for="{{item}}" wx:for-item="it" wx:key="{{index}}" data-newsid="{{it.new_id}}" text="{{it.new_topic}}" /> </swiper-item> </swiper> </view>
wxss
swiper-item { height: 100%; }
js
//index.js //獲取應(yīng)用實(shí)例 import api from "../../utils/api.js" var token = '' const app = getApp() Page({ data: { topnewslist:[] }, onLoad: function () { }, tonewsdetail(e){ var newsid=e.currentTarget.dataset.newsid; wx.navigateTo({ url: '/pages/newsdetail/newsdetail?newsid='+newsid, }) }, loadscrollnews(){ api.get("mpapi/mpmnews.ashx", { action:'toplist',token:token}).then((res)=>{ if(res.code==1){ //res.list=[{"new_id":1,"new_topic":"111"},{"new_id":2,"new_topic":"222"},{"new_id":3,"new_topic":"333"},{"new_id":4,"new_topic":"444"}] this.setData({ topnewslist: this.splitArr(res.list, 2) //調(diào)用 //調(diào)用之后[[{"new_id":1,"new_topic":"111"},{"new_id":2,"new_topic":"222"}],[{"new_id":3,"new_topic":"333"},{"new_id":4,"new_topic":"444"}]] }) } }) }, /** * 分割數(shù)組創(chuàng)建二維數(shù)組封裝 * @param data 數(shù)組 * @param senArrLen 需要分割成子數(shù)組的長(zhǎng)度 */ splitArr(data, senArrLen){ //處理成len個(gè)一組的數(shù)據(jù) let data_len = data.length; let arrOuter_len = data_len % senArrLen === 0 ? data_len / senArrLen : parseInt((data_len / senArrLen) + '') + 1; let arrSec_len = data_len > senArrLen ? senArrLen : data_len;//內(nèi)層數(shù)組的長(zhǎng)度 let arrOuter = new Array(arrOuter_len);//最外層數(shù)組 let arrOuter_index = 0;//外層數(shù)組的子元素下標(biāo) // console.log(data_len % len); for (let i = 0; i < data_len; i++) { if (i % senArrLen === 0) { arrOuter_index++; let len = arrSec_len * arrOuter_index; //將內(nèi)層數(shù)組的長(zhǎng)度最小取決于數(shù)據(jù)長(zhǎng)度對(duì)len取余,平時(shí)最內(nèi)層由下面賦值決定 arrOuter[arrOuter_index - 1] = new Array(data_len % senArrLen); if (arrOuter_index === arrOuter_len)//最后一組 data_len % senArrLen === 0 ? len = data_len % senArrLen + senArrLen * arrOuter_index : len = data_len % senArrLen + senArrLen * (arrOuter_index - 1); let arrSec_index = 0;//第二層數(shù)組的索引 for (let k = i; k < len; k++) {//第一層數(shù)組的開(kāi)始取決于第二層數(shù)組長(zhǎng)度*當(dāng)前第一層的索引 arrOuter[arrOuter_index - 1][arrSec_index] = data[k]; arrSec_index++; } } } return arrOuter }, // 截獲豎向滑動(dòng) catchTouchMove: function (res) { return false }, })
上述就是小編為大家分享的怎么在微信小程序中實(shí)現(xiàn)一個(gè)多行文字滾動(dòng)效果了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。