The examples in this article are all written in small programs, but this does not affect the functions to be implemented. wxml Make one more copy of the box containing the picture so that the beginning and end of the looped picture are connected <view class="scrollbox dis-flex"> <view class="imgItem dis-flex" style="animation: {{computedAni}};"> <image src="../img/{{index + 1}}.jpg" wx:for="{{images}}" mode="aspectFill" wx:key="index"></image> </view> <view class="imgItem dis-flex" style="animation: {{computedAni}};"> <image src="../img/{{index + 1}}.jpg" wx:for="{{images}}" mode="aspectFill" wx:key="index"></image> </view> </view> wxss .dis-flex { display: flex; display: -webkit-flex; } .scrollbox { margin: 30px; text-align: center; border: 1px solid blue; height: 220rpx; align-items: center; overflow: hidden; } .imgItem { animation: 24s rowup linear infinite normal; } .imgItem image { width: 200rpx; height: 200rpx; margin: 0 20rpx; } @keyframes rowup { 0% { -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); } 100% { -webkit-transform: translate3d(-100%, 0, 0); transform: translate3d(-100%, 0, 0); } } @-webkit-keyframes rowup { 0% { -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); } 100% { -webkit-transform: translate3d(-1000px, 0, 0); transform: translate3d(-1000px, 0, 0); } } js The key to adjusting the speed is that the animation time is dynamically controlled by the number of looped items. Page({ data: { images: new Array(4), computedAni: '' }, onLoad: function () { this.setAniSpeed(this.data.images.length) }, setAniSpeed(num) { let time = Math.ceil(num / 5 * 15) // Here, the animation time is 15s when there are 5 pictures. You can adjust it yourself this.setData({ computedAni: `${time}s rowup linear infinite normal` }) } }) Click here to view the code snippet https://developers.weixin.qq.com/s/4gGngEm67Zlh This concludes this article about the sample code for implementing horizontal infinite scrolling with pure CSS3. For more relevant CSS3 horizontal infinite scrolling content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: Double loading issue when the page contains img src
>>: How to use the href attribute of the HTML a tag to specify relative and absolute paths
Table of contents rem vw Adapt to third-party UI ...
Table of contents Preface Create a Vite project R...
Table of contents vue2.x Pre-concept: Routing hoo...
Some time ago, I submitted a product version to t...
Table of contents 1. Introduction to platform bus...
Table of contents Preface Introduction to Closure...
Zabbix Server Environment Platform Version: ZABBI...
I spent a day on it before this. Although Seata i...
Table of contents Preface 1. The process of using...
Preface: In some previous articles, we often see ...
This article introduces the import and export of ...
I wrote a jsp page today. I tried to adjust <di...
I wrote a test program before, in which adding and...
Dockerfile is a text file used to build an image....
Table of contents 1. Install vmware 1.1 Download ...