小編給大家分享一下純css3如何實現橫向無限滾動,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
wxml
裝圖片的盒子多復制一份,讓循環圖片的首尾相接
<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
調整速度的關鍵就在,動畫的時間是由循環的項目個數動態控制的
Page({
data: {
images: new Array(4),
computedAni: ''
},
onLoad: function () {
this.setAniSpeed(this.data.images.length)
},
setAniSpeed (num) {
let time = Math.ceil(num / 5 * 15) // 這里是以5張圖片的時候,動畫時間15s為基準,可以自己調節
this.setData({
computedAni: `${time}s rowup linear infinite normal`
})
}
})以上是“純css3如何實現橫向無限滾動”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。