亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序?qū)崿F(xiàn)文字從右向左無限滾動(dòng)

 更新時(shí)間:2020年11月18日 09:24:52   作者:林羽凡  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)文字從右向左無限滾動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)文字無限滾動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下

布局頁面wxml

<scroll-view class="container">
 <view class="scrolltxt">
 <view class="marquee_box">
  <view class="marquee_text" style="transform: translateX(-{{marqueeDistance}}px)">
  <text>{{text}}</text>
  <text style="margin-right:{{marquee_margin}}px;"></text>
  <text style="margin-right:{{marquee_margin}}px;">{{text}}</text>  
  </view>
 </view>
 </view>
</scroll-view>

樣式頁面 wxss

.container {height: 100%;display: flex;flex-direction: column;justify-content: space-between;box-sizing: border-box;}
.scrolltxt{padding:0 20rpx;background:#f8f8f8;}
.marquee_box {position:relative;color:#333;height:90rpx;display:block;overflow:hidden;} 
.marquee_text {white-space: nowrap;position:absolute;top:0;font-size:14px;height:90rpx;line-height:90rpx;}

小程序 js頁面

Page({
 /**
 * 頁面的初始數(shù)據(jù)
 * Linyufan.com
 */
 data: {
 text: "這是一條測(cè)試公告,看看效果怎么樣,2019年3月23日",
 marqueePace: 1,//滾動(dòng)速度
 marqueeDistance: 0,//初始滾動(dòng)距離
 marquee_margin: 30,
 size:14,
 interval: 20 // 時(shí)間間隔
 },
 
 /**
 * 生命周期函數(shù)--監(jiān)聽頁面加載
 */
 onLoad: function (options) { 
 },
 onShow: function () {
 var that = this;
 var length = that.data.text.length * that.data.size;//文字長(zhǎng)度
 var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕寬度
 //console.log(length,windowWidth);
 that.setData({
  length: length,
  windowWidth: windowWidth
 });
 that.scrolltxt();// 第一個(gè)字消失后立即從右邊出現(xiàn)
 },
 
 scrolltxt: function () {
 var that = this;
 var length = that.data.length;//滾動(dòng)文字的寬度
 var windowWidth = that.data.windowWidth;//屏幕寬度
 if (length > windowWidth){
  var interval = setInterval(function () {
  var maxscrollwidth = length + that.data.marquee_margin;//滾動(dòng)的最大寬度,文字寬度+間距,如果需要一行文字滾完后再顯示第二行可以修改marquee_margin值等于windowWidth即可
  var crentleft = that.data.marqueeDistance;
  if (crentleft < maxscrollwidth) {//判斷是否滾動(dòng)到最大寬度
   that.setData({
   marqueeDistance: crentleft + that.data.marqueePace
   })
  }
  else {
   //console.log("替換");
   that.setData({
   marqueeDistance: 0 // 直接重新滾動(dòng)
   });
   clearInterval(interval);
   that.scrolltxt();
  }
  }, that.data.interval);
 }
 else{
  that.setData({ marquee_margin:"1000"});//只顯示一條不滾動(dòng)右邊間距加大,防止重復(fù)顯示
 } 
 }
})

為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論