微信小程序?qū)崿F(xiàn)無縫滾動
更新時間:2021年03月16日 15:45:16 作者:Edward_Cullens
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)無縫滾動,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了微信小程序?qū)崿F(xiàn)無縫滾動的具體代碼,供大家參考,具體內(nèi)容如下
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;//文字+圖標(biāo)長度 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); //調(diào)用滾動方法 }).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; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript中null和undefined的區(qū)別詳解
null 是一個原始值,表示“無”或“空值”,它通常用于指示變量應(yīng)有的對象或值不存在,undefined 是一個原始值,表示“未定義”,本文給大家詳細(xì)介紹了JavaScript中null和undefined的區(qū)別,需要的朋友可以參考下2024-10-10JS+CSS實現(xiàn)電子商務(wù)網(wǎng)站導(dǎo)航模板效果代碼
這篇文章主要介紹了JS+CSS實現(xiàn)電子商務(wù)網(wǎng)站導(dǎo)航模板效果代碼,涉及JavaScript結(jié)合css動態(tài)操作頁面元素屬性的相關(guān)技巧,非常具有實用價值,需要的朋友可以參考下2015-09-09javascript實現(xiàn)tabs選項卡切換效果(擴展版)
常用的頁面效果有彈出層效果,無縫滾動效果,選項卡切換效果,接下來與大家分享一款自己用原生javascript寫的選項卡切換效果在原有的基礎(chǔ)上進行了擴展,加入了自動輪播,這樣就變成了類似圖片輪播的效果2013-03-03微信小程序 功能函數(shù)小結(jié)(手機號驗證*、密碼驗證*、獲取驗證碼*)
這篇文章主要介紹了微信小程序功能函數(shù)手機號驗證、密碼驗證,獲取驗證碼*的相關(guān)代碼,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-12-12