本篇文章主要介紹了微信小程序-滾動(dòng)消息通知的實(shí)例代碼,內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。
寫(xiě)在前面:
這次我主要想總結(jié)一下微信小程序?qū)崿F(xiàn)上下滾動(dòng)消息提醒,主要是利用swiper組件來(lái)實(shí)現(xiàn),swiper組件在小程序中是滑塊視圖容器。
我們通過(guò)vertical屬性(默認(rèn)為false,實(shí)現(xiàn)默認(rèn)左右滾動(dòng))設(shè)置為true來(lái)實(shí)現(xiàn)上下滾動(dòng)。
(需要注意的是:只要你的swiper存在vertical屬性,無(wú)論你給值為true或者false或者不設(shè)參數(shù)值,都將實(shí)現(xiàn)上下滾動(dòng))
從深圳回來(lái)做了一個(gè)微信小程序的小項(xiàng)目,令人欣慰的一點(diǎn)事是,回來(lái)很快時(shí)間內(nèi)把在深圳兩天的房租給賺回來(lái)了,哈哈…
wxml
<swiper class="swiper_container" vertical="true" autoplay="true" circular="true" interval="2000">
<block wx:for="{{msgList}}">
<navigator url="/pages/index/index?title={{item.url}}" open-type="navigate">
<swiper-item>
<view class="swiper_item">{{item.title}}</view>
</swiper-item>
</navigator>
</block>
</swiper>
wxss
.swiper_container {
height: 55rpx;
width: 80vw;
}
.swiper_item {
font-size: 25rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
letter-spacing: 2px;
}
Js
var app = getApp()
Page({
data: {
},
onLoad(e) {
console.log(e.title)
this.setData({
msgList: [
{ url: "url", title: "公告:多地首套房貸利率上浮 熱點(diǎn)城市漸迎零折扣時(shí)代" },
{ url: "url", title: "公告:悅?cè)绻⑷苣晟张垦忝赓M(fèi)吃喝歡唱" },
{ url: "url", title: "公告:你想和一群有志青年一起過(guò)生日嘛?" }]
});
}
})
數(shù)據(jù)放在了setData函數(shù)中,setData函數(shù)的主要作用是將數(shù)據(jù)從邏輯層發(fā)送到視圖層,但是需要避免單次設(shè)置大量的數(shù)據(jù)。
效果

寫(xiě)在后面
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,更多相關(guān)內(nèi)容請(qǐng)關(guān)注PHP中文網(wǎng)!
相關(guān)推薦:
以上就是微信小程序中滾動(dòng)消息通知的實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注有卡有網(wǎng)。




