最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序?qū)崿F(xiàn)文字滾動(dòng)

 更新時(shí)間:2021年03月16日 14:25:26   作者:huangzhin  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)文字滾動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

wxml:

<view>顯示完后再顯示:</view>
<view class="example">
 <view class="box">
 <view class="text" style="{{orientation}}:{{marqueeDistance}}px;font-size: {{size}}px;">
  {{text}}
 </view>
 </view>
</view>
<view>出現(xiàn)白邊后即顯示:</view>
<view class="example">
 <view class="box">
 <view class="text" style="{{orientation}}:{{marqueeDistance2}}px;font-size: {{size}}px;">
  <text>{{text}}</text>
  <text wx:if="{{marquee2copy_status}}" style="margin-left:{{marquee2_margin}}px;">{{text}}</text>
 </view>
 </view>
</view>

wxss:

.example {
 display: block;
 width: 100%;
 height: 100rpx;
}

.box {
 width: 100%;
 position: relative;
}

.text {
 white-space: nowrap;
 position: absolute;
 top: 0;
}

js:

Page({


 data: {
 text: '滾動(dòng)文本1234567890abcdefghijklmnopqrstuvmxyz',
 marqueePace: 1, //滾動(dòng)速度
 marqueeDistance: 0, //初始滾動(dòng)距離
 marqueeDistance2: 0,
 marquee2copy_status: false,
 marquee2_margin: 60,
 size: 14,
 orientation: 'left', //滾動(dòng)方向
 interval: 20 // 時(shí)間間隔
 },
 onShow: function() {
 // 頁面顯示
 var vm = this;
 var length = vm.data.text.length * vm.data.size; //文字長度
 var windowWidth = wx.getSystemInfoSync().windowWidth; // 屏幕寬度
 vm.setData({
  length: length,
  windowWidth: windowWidth,
  marquee2_margin: length < windowWidth ? windowWidth - length : vm.data.marquee2_margin //當(dāng)文字長度小于屏幕長度時(shí),需要增加補(bǔ)白
 });
 vm.run1(); // 水平一行字滾動(dòng)完了再按照原來的方向滾動(dòng)
 vm.run2(); // 第一個(gè)字消失后立即從右邊出現(xiàn)
 },
 run1: function() {
 var vm = this;
 var interval = setInterval(function() {
  if (-vm.data.marqueeDistance < vm.data.length) {
  vm.setData({
   marqueeDistance: vm.data.marqueeDistance - vm.data.marqueePace,
  });
  } else {
  clearInterval(interval);
  vm.setData({
   marqueeDistance: vm.data.windowWidth
  });
  vm.run1();
  }
 }, vm.data.interval);
 },
 run2: function() {
 var vm = this;
 var interval = setInterval(function() {
  if (-vm.data.marqueeDistance2 < vm.data.length) {
  // 如果文字滾動(dòng)到出現(xiàn)marquee2_margin=30px的白邊,就接著顯示
  vm.setData({
   marqueeDistance2: vm.data.marqueeDistance2 - vm.data.marqueePace,
   marquee2copy_status: vm.data.length + vm.data.marqueeDistance2 <= vm.data.windowWidth + vm.data.marquee2_margin,
  });
  } else {
  if (-vm.data.marqueeDistance2 >= vm.data.marquee2_margin) { // 當(dāng)?shù)诙l文字滾動(dòng)到最左邊時(shí)
   vm.setData({
   marqueeDistance2: vm.data.marquee2_margin // 直接重新滾動(dòng)
   });
   clearInterval(interval);
   vm.run2();
  } else {
   clearInterval(interval);
   vm.setData({
   marqueeDistance2: -vm.data.windowWidth
   });
   vm.run2();
  }
  }
 }, vm.data.interval);
 }


})

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

相關(guān)文章

最新評論

东平县| 三穗县| 闵行区| 广州市| 沅陵县| 鹤岗市| 石景山区| 资源县| 民权县| 陆良县| 鄱阳县| 万山特区| 浑源县| 桐柏县| 武汉市| 遂溪县| 新乐市| 保德县| 格尔木市| 陵水| 凉山| 宜州市| 和政县| 伊宁县| 隆德县| 荃湾区| 福安市| 辽阳市| 三亚市| 孟津县| 鄂尔多斯市| 绥滨县| 仲巴县| 双鸭山市| 台北县| 汝阳县| 汉中市| 贡山| 来凤县| 水城县| 娄底市|