文中实例全是用微信小程序写的,可是不危害要完成的作用。
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` }) } })
点一下这儿能够查询编码片断
https://developers.weixin.qq.com/s/4gGngEm67Zlh
到此这篇有关纯css3完成横着无尽翻转的实例编码的文章内容就详细介绍到这了,大量有关css3横着无尽翻转內容请检索脚本制作之家之前的文章内容或再次访问下边的有关文章内容,期待大伙儿之后多多的适用脚本制作之家!