微信小程序?qū)崿F(xiàn)多行文字滾動效果
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)多行文字滾動的具體代碼,供大家參考,具體內(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ù)組的長度
*/
splitArr(data, senArrLen){
//處理成len個一組的數(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ù)組的長度
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ù)組的長度最小取決于數(shù)據(jù)長度對len取余,平時最內(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ù)組的開始取決于第二層數(shù)組長度*當(dāng)前第一層的索引
arrOuter[arrOuter_index - 1][arrSec_index] = data[k];
arrSec_index++;
}
}
}
return arrOuter
},
// 截獲豎向滑動
catchTouchMove: function (res) {
return false
},
})以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
比較簡單的一個符合web標(biāo)準(zhǔn)的JS調(diào)用flash方法
比較簡單的一個符合web標(biāo)準(zhǔn)的JS調(diào)用flash方法...2007-11-11
JS實(shí)現(xiàn)讓網(wǎng)頁背景圖片斜向移動的方法
這篇文章主要介紹了JS實(shí)現(xiàn)讓網(wǎng)頁背景圖片斜向移動的方法,涉及javascript操作背景圖片特效的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-02-02
使用原生JavaScript實(shí)現(xiàn)放大鏡效果
這篇文章主要為大家詳細(xì)介紹了如何使用原生JavaScript實(shí)現(xiàn)放大鏡效果(可自由大小適配),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2023-03-03
javascript中的Function.prototye.bind
這篇文章主要介紹了javascript中的Function.prototye.bind的相關(guān)資料,需要的朋友可以參考下2015-06-06
微信小程序項(xiàng)目實(shí)踐之主頁tab選項(xiàng)實(shí)現(xiàn)
這篇文章主要介紹了微信小程序項(xiàng)目實(shí)踐之主頁tab選項(xiàng)實(shí)現(xiàn),本文通過實(shí)例代碼相結(jié)合的形式給大家介紹的非常詳細(xì),需要的朋友可以參考下2018-07-07
Bootstrap3 圖片(響應(yīng)式圖片&圖片形狀)
這篇文章主要介紹了 Bootstrap3 圖片 響應(yīng)式圖片和圖片形狀的相關(guān)資料,需非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-01-01
JavaScript實(shí)現(xiàn)url參數(shù)轉(zhuǎn)成json形式
這篇文章主要介紹了JavaScript實(shí)現(xiàn)url參數(shù)轉(zhuǎn)成json形式的相關(guān)代碼,有喜歡的小伙伴可以參考下2016-09-09
使用JavaScript實(shí)現(xiàn)實(shí)時搜索建議功能
在我們的技術(shù)旅程中,JavaScript 無疑是一個不可或缺的伙伴,這篇文章主要為大家詳細(xì)介紹了如何使用 JavaScript 來實(shí)現(xiàn)一個復(fù)雜功能,即實(shí)時搜索建議,感興趣的可以了解下2024-02-02

