您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關微信小程序怎么實現無縫滾動的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
具體內容如下
wxml
<view class="wrap-item" style='transform:translateX({{posLeft2}}px)'> <view class="messages-scroll firstScroll"> <view class="{{index == 0?'yanse items':'items'}}" wx:for="{{zhuli}}" wx:key="index"> <image wx:if="{{index == 0}}" src="../../images/xiangq_yonhu_icon_p.png"></image> <image wx:if="{{index != 0}}" src="../../images/xiangq_yonhu_icon_n.png"></image> <view>{{index}}{{item.ip}}{{item.str}}</view> </view> </view> <view class="messages-scroll secondScroll" style='transform:translateX({{marginLeft}}px)'> <view class="{{index == 0?'yanse items':'items'}}" wx:for="{{zhuli}}" wx:key="index"> <image wx:if="{{index == 0}}" src="../../images/xiangq_yonhu_icon_p.png"></image> <image wx:if="{{index != 0}}" src="../../images/xiangq_yonhu_icon_n.png"></image> <view>{{item.ip}}{{item.str}}</view> </view> </view> </view>
JS
onShow(){ let windowWidth = wx.getSystemInfoSync().windowWidth; //屏幕寬度 wx.createSelectorQuery().select('.firstScroll').boundingClientRect(function (rect) { let txtLength = rect.width;//文字+圖標長度 console.log(txtLength) console.log(rect) // that.setData({ // marginLeft: txtLength < windowWidth - that.data.marginLeft ? windowWidth - txtLength : that.data.marginLeft // }) console.log(that.data.marginLeft) that.roll2(that, txtLength, windowWidth); //調用滾動方法 }).exec() }, roll2: function (that, txtLength, windowWidth) { var interval2 = setInterval(function () { if (-that.data.posLeft2 < txtLength) { that.setData({ posLeft2: that.data.posLeft2 - that.data.pace }) } else { // 第二段文字滾動到左邊后重新滾動 that.setData({ posLeft2: 0 }) clearInterval(interval2); that.roll2(that, txtLength, windowWidth); } }, 20) },
wxss:
.wrap-item{ position: relative; z-index: 10; display: flex; white-space: nowrap; } .brand-info .messages-scroll { display: flex; white-space: nowrap; margin-top: 148rpx; } .brand-info .messages-scroll .items { display: flex; white-space: nowrap; box-sizing: border-box; padding: 0 10rpx; margin-left: 10rpx; align-items: center; /* width: 332rpx; */ height: 50rpx; background: rgba(0, 0, 0, 0.2); border-radius: 25rpx; color: #99A4BA; } .yanse{ color: #C4FFFD !important; } .brand-info .messages-scroll .items image { width: 26rpx; height: 22rpx; margin-right: 10rpx; } .brand-info .messages-scroll .items view { font-size: 24rpx; font-family: Source Han Sans CN; font-weight: 400; }
感謝各位的閱讀!關于“微信小程序怎么實現無縫滾動”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。