这篇文章给大家分享的是有关微信小程序怎么实现无缝滚动的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
具体内容如下
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;
}
感谢各位的阅读!关于“微信小程序怎么实现无缝滚动”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。