手写banner切换方式

编程入门 行业动态 更新时间:2024-10-26 05:32:46

手写banner切换<a href=https://www.elefans.com/category/jswz/34/1771414.html style=方式"/>

手写banner切换方式

<template><!-- banner轮播切换 --><div class="banner-wrapper"><div class="banner-info"><ul class="box" ref="box"><li v-for="(item, index) in bannerList" :key="index"><img :src="item.img" alt="" /></li></ul></div></div>
</template><script>
export default {name: '',data() {return {bannerList: [{ img: '/img/ocean_bck.png' },{ img: '/img/bck.png' },{ img: '/img/ocean_bck.png' },{ img: '/img/bck.png' },{ img: '/img/ocean_bck.png' },{ img: '/img/bck.png' },{ img: '/img/ocean_bck.png' },// { img: '/img/bck.png' }],timer: null,oBox: '',leftVal: 0,count: 0,iconCount: 0,screenWidth: document.body.clientWidth, // 获取屏幕宽度textList: []}},mounted() {let repeat = [this.bannerList[0]]this.bannerList = this.bannerList.concat(repeat)this.inits()},methods: {inits() {this.oBox = this.$refs.box;/*this.count等于0,播放第一张,this.count等于1,播放第二张,以此类推*/this.timer = setInterval(() => {this.leftVal = `-${838 + 838 * this.count}px` //左边的left值this.count++let len = this.bannerList.length //轮播图片总张数if (this.count === len) {/*临界值,此时最后一张图片已经播放完了,最后一张图和第一张图是一样的,目的是为了无缝衔接,此时需要跳转到第一张图片,随后瞬间滑到第二张图,达到无缝观感*/this.count = 1; //为了下次循环开始跳转第三张,所以设置为1this.oBox.style.transition = `all 0s ease-in-out`;this.oBox.style.left = 0;this.setTimeoutTimer = setTimeout(() => {this.oBox.style.transition = `all 0.5S ease-in-out`;// this.oBox.style.opacity = `0`this.oBox.style.left = `-` + 838 + `px`;clearTimeout(this.setTimeoutTimer)this.setTimeoutTimer = null}, 200);} else { //正常循环this.oBox.style.transition = `all 0.5S ease-in-out`;// this.oBox.style.opacity = `0`this.oBox.style.left = this.leftVal}}, 2000)},},
}
</script><style scoped>
.banner-wrapper {width: 100%;height: 100%;
}.banner-info {width: 50%;height: 100%;margin: 0 auto;position: relative;overflow: hidden;
}.box {display: flex;position: absolute;transition: all 0.5S ease-in-out;left: 0;
}.box>li>img {width: 838px;
}
</style>

更多推荐

手写banner切换方式

本文发布于:2023-12-04 19:28:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1661991.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   banner

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!