Sample code for implementing horizontal infinite scrolling with pure CSS3

Sample code for implementing horizontal infinite scrolling with pure CSS3

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

Recommend

How to implement Docker container self-start

Container auto-start Docker provides a restart po...

Mac+IDEA+Tomcat configuration steps

Table of contents 1. Download 2. Installation and...

How to set up vscode remote connection to server docker container

Table of contents Pull the image Run the image (g...

Tips for implementing multiple borders in CSS

1. Multiple borders[1] Background: box-shadow, ou...

Thumbnail hover effect implemented with CSS3

Achieve resultsImplementation Code html <heade...

Implementation of Docker deployment of MySQL cluster

Disadvantages of single-node database Large-scale...

Detailed Introduction to the MySQL Keyword Distinct

Introduction to the usage of MySQL keyword Distin...

js canvas realizes circular water animation

This article example shares the specific code of ...

js to achieve 3D carousel effect

This article shares the specific code for impleme...

How to implement https with nginx and openssl

If the server data is not encrypted and authentic...

docker-maven-plugin packages the image and uploads it to a private warehouse

Table of contents 1. Introduction to docker-maven...

The "3I" Standards for Successful Print Advertising

For many domestic advertisers, the creation and ev...