vue+animation動(dòng)畫實(shí)現(xiàn)跑馬燈效果
本文實(shí)例為大家分享了vue+animation動(dòng)畫實(shí)現(xiàn)跑馬燈效果的具體代碼,供大家參考,具體內(nèi)容如下
1、單行顯示,每行只顯示一條
效果圖

上代碼
<template>
? <div class="container">
? ? <div class="box">
? ? ? <!-- 假設(shè)lists列表有4個(gè)項(xiàng),設(shè)置ul的寬度為800%(相對(duì)于box),設(shè)置li的寬度為12.5%(相對(duì)于ul是12.5%;相對(duì)于box是100%),但是li要有8個(gè),其中4個(gè)是復(fù)制的,用來(lái)占位 -->
? ? ? <ul :style="'width:' + lists.length * 100 * 2 + '%;animation-duration:' + lists.length*2 + 's;'">
? ? ? ? <li :style="'width:' + 100 / (lists.length * 2) + '%;'" v-for="(item, index) in lists" :key="index">
? ? ? ? ? <div class="content">{{item.name}}</div>
? ? ? ? </li>
? ? ? ? <li :style="'width:' + 100 / (lists.length * 2) + '%;'" v-for="(item, index) in lists" :key="index">
? ? ? ? ? <div class="content">{{item.name}}</div>
? ? ? ? </li>
? ? ? </ul>
? ? </div>
? </div>
</template>
<script>
export default {
? name: "activity",
? data() {
? ? return {
? ? ? lists: [
? ? ? ? { name: "馬云阿薩" },
? ? ? ? { name: "雷軍的" },
? ? ? ? { name: "王勤啊啊啊啊" },
? ? ? ? { name: "等倫倫" }
? ? ? ]
? ? };
? },
};
</script>
<style scoped>
.box {
? width: 100%;
? height: 0.6rem;
? background-color: #b32855;
? overflow: hidden;
}
.box ul {
? animation-name: move;
? /* 在style中動(dòng)態(tài)設(shè)置每一個(gè)li花費(fèi)的時(shí)間為2s */
? /* animation-duration: 8s; */
? animation-timing-function: linear;
? animation-iteration-count: infinite;
}
ul li {
? float: left;
? height: 0.6rem;
? display: flex;
? align-items: center;
}
ul li .content {
? height: 0.4rem;
? padding: 0 0.2rem;
? border-radius: 0.2rem;
? background-color: rgba(0, 0, 0, 0.2);
? color: #fff;
? display: flex;
? align-items: center;
? justify-content: space-around;
}
@keyframes move {
? 0% {
? ? transform: translateX(0);
? }
? 100% {
? ? /* 平移自身寬度的50%,ul寬度的50%,剩下的那50%用來(lái)在下一次顯示時(shí)占位 */
? ? transform: translateX(-50%);
? }
}
</style>2、單行顯示,每行顯示多條
效果圖

上代碼
<template>
? <div class="container">
? ? <div class="box">
? ? ? <!-- 假設(shè)lists列表有4個(gè)項(xiàng),設(shè)置ul的寬度為400%(相對(duì)于box),設(shè)置li的寬度為12.5%(相對(duì)于ul是12.5%;相對(duì)于box是50%),但是li要有8個(gè),其中4個(gè)是復(fù)制的,用來(lái)占位 -->
? ? ? <ul :style="'width:' + lists.length * 100 + '%;animation-duration:' + lists.length*2 + 's;'">
? ? ? ? <li :style="'width:' + 100 / (lists.length * 2) + '%;'" v-for="(item, index) in lists" :key="index">
? ? ? ? ? <div class="content">{{item.name}}</div>
? ? ? ? </li>
? ? ? ? <li :style="'width:' + 100 / (lists.length * 2) + '%;'" v-for="(item, index) in lists" :key="index">
? ? ? ? ? <div class="content">{{item.name}}</div>
? ? ? ? </li>
? ? ? </ul>
? ? </div>
? </div>
</template>以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue實(shí)現(xiàn)動(dòng)態(tài)顯示與隱藏底部導(dǎo)航的方法分析
這篇文章主要介紹了vue實(shí)現(xiàn)動(dòng)態(tài)顯示與隱藏底部導(dǎo)航的方法,結(jié)合實(shí)例形式分析了vue.js針對(duì)導(dǎo)航隱藏與顯示的路由配置、事件監(jiān)聽等相關(guān)操作技巧,需要的朋友可以參考下2019-02-02
vue使用el-upload實(shí)現(xiàn)文件上傳功能
這篇文章主要為大家詳細(xì)介紹了vue使用el-upload實(shí)現(xiàn)文件上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
Vue3獲取和操作DOM元素的項(xiàng)目實(shí)踐
在Vue3中,有時(shí)我們需要直接操作DOM節(jié)點(diǎn),本文主要介紹了Vue3獲取和操作DOM元素的項(xiàng)目實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-08-08
vue父組件向子組件(props)傳遞數(shù)據(jù)的方法
這篇文章主要介紹了vue父組件向子組件(props)傳遞數(shù)據(jù)的方法,文中給大家補(bǔ)充介紹了vue父子組件間傳值(props)的實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-01-01
Vue3中使用vuedraggable拖拽實(shí)戰(zhàn)教程
這篇文章主要介紹了Vue3中使用vuedraggable拖拽實(shí)戰(zhàn)教程,文中通過(guò)示例介紹了vue3拖拽組件vuedraggable的使用demo,需要的朋友可以參考下2023-06-06
vue3?關(guān)于reactive的重置問(wèn)題及解決
這篇文章主要介紹了vue3?關(guān)于reactive的重置問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05

