本文实例为大家分享了微信小程序实现多行文字滚动的具体代码,供大家参考,具体内容如下

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
//获取应用实例
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"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) //调用
//调用之后[[{"new_id":1,"new_topic":"111"},{"new_id":2,"new_topic":"222"}],[{"new_id":3,"new_topic":"333"},{"new_id":4,"new_topic":"444"}]]
})
}
})
},
/**
* 分割数组创建二维数组封装
* @param data 数组
* @param senArrLen 需要分割成子数组的长度
*/
splitArr(data, senArrLen){
//处理成len个一组的数据
let data_len = data.length;
let arrOuter_len = data_len % senArrLen === 0 "_blank" href="//www.jb51.net/Special/900.htm">《微信小程序开发教程》小编为大家精心整理的,希望喜欢。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。