微信小程序实现无缝滚动
网络编程 2021-07-04 14:07www.168986.cn编程入门
这篇文章主要为大家详细介绍了微信小程序实现无缝滚动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了微信小程序实现无缝滚动的具体代码,供大家参考,具体内容如下
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-: 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; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
上一篇:微信小程序实现走马灯效果实例
下一篇:微信小程序实现文字滚动
编程语言
- 甘肃哪有关键词排名优化购买方式有哪些
- 甘肃SEO如何做网站优化
- 河南seo关键词优化怎么做电话营销
- 北京SEO优化如何做QQ群营销
- 来宾百度关键词排名:提升您网站曝光率的关键
- 卢龙关键词优化:提升您网站排名的策略与技巧
- 山东网站优化的注意事项有哪些
- 四川整站优化怎样提升在搜索引擎中的排名
- 疏附整站优化:提升网站性能与用户体验的全新
- 海南seo主要做什么工作售后服务要做到哪些
- 荣昌百度网站优化:提升您网站的搜索引擎排名
- 河北seo网站排名关键词优化如何做SEO
- 江西优化关键词排名推广售后保障一般有哪些
- 古浪SEO优化:提升你的网站可见性
- 西藏网站排名优化怎么把网站排名在百度首页
- 如何提升阳东百度快照排名:详尽指南