先看看效果
话不多说直接上代码
<template><div class="main"><div class="scroll-region"><div class="swiper-scroll-content"><span class="list-btn" v-for="(item, index) in overviewList" :key="index">{{ item }}</span></div></div></div>
</template>
<script>
export default {data() {return {overviewList: ['富强', '民主', '文明', '和谐', '自由', '平等', '公正', '法治', '爱国', '敬业', '诚信', '友善', '富强', '民主', '文明', '和谐', '自由', '平等', '公正', '法治',]}}
}
</script>
<style scoped>
.main {display: flex;justify-content: center;align-items: center;margin: 100px 0 0 0;background: #2f44e6;
}
.scroll-region {width: 60%;overflow: hidden;
}
@keyframes roll {0% {transform: translateX(0%);}100% {transform: translateX(-153%);}
}
.swiper-scroll-content {display: flex;align-items: center;white-space: nowrap;animation: roll 25s infinite linear;
}
@keyframes animated-border {0% {box-shadow: 0 0 0 0 rgba(255,255,255,0.4);}100% {outline: 5px solid rgba(255,255,255,0);outline-offset: -5px;}
}
.list-btn {padding: 10px 20px;margin: 0 11px;color: #6DFFFF;border-radius: 20px;animation: animated-border 1.5s infinite;font-family: Arial;font-size: 18px;line-height: 30px;font-weight: bold;
}
</style>
主要修改点有两个:
- transform: translateX(-153%),这里需要自己根据情况更改衔接,保证轮播是连贯不断地。
- 通过overviewList的尾部添加重复文本,配合transform来实现轮播连贯。