微信小程序?qū)崿F(xiàn)多行文字滾動(dòng)效果
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)多行文字滾動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下
wxml
<view class="full" style="height:100%;overflow:hidden"> <swiper autoplay="true" interval="3000" duration="500" circular="true" vertical="true" style="height:100%"> <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}}" style="width:100%" 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 }, })
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
一文詳解requestAnimationFrame請(qǐng)求動(dòng)畫(huà)幀
requestAnimationFrame是一個(gè)用于動(dòng)畫(huà)效果的 API,它使用瀏覽器的刷新率來(lái)執(zhí)行回調(diào)函數(shù),通常每秒鐘執(zhí)行60次,這篇文章主要給大家介紹了關(guān)于requestAnimationFrame請(qǐng)求動(dòng)畫(huà)幀的相關(guān)資料,需要的朋友可以參考下2023-12-12javascript實(shí)現(xiàn)簡(jiǎn)單的鼠標(biāo)拖動(dòng)效果實(shí)例
這篇文章主要介紹了javascript實(shí)現(xiàn)簡(jiǎn)單的鼠標(biāo)拖動(dòng)效果,實(shí)例分析了javascript鼠標(biāo)拖動(dòng)效果的相關(guān)要點(diǎn)與實(shí)現(xiàn)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04js 客戶端打印html 并且去掉頁(yè)眉、頁(yè)腳的實(shí)例
下面小編就為大家?guī)?lái)一篇js 客戶端打印html 并且去掉頁(yè)眉、頁(yè)腳的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11JavaScript數(shù)據(jù)類型檢測(cè)實(shí)現(xiàn)方法詳解
Javascript中檢查數(shù)據(jù)類型一直是老生常談的問(wèn)題,類型判斷在web開(kāi)發(fā)中也有著非常廣泛的應(yīng)用,所以下面這篇文章主要給大家介紹了關(guān)于JS數(shù)據(jù)類型檢測(cè)的那些事,需要的朋友可以參考下2022-11-11js針對(duì)ip地址、子網(wǎng)掩碼、網(wǎng)關(guān)的邏輯性判斷
這篇文章主要介紹了js針對(duì)ip地址、子網(wǎng)掩碼、網(wǎng)關(guān)的邏輯性判斷,感興趣的小伙伴們可以參考一下2016-01-01