需要自动滚动循环播放的列表,使用纯CSS实现基础循环功能
.messages animation-name carousel animation-timing-function linear animation-iteration-count infinite .message-item cursor pointer margin-top 10px &.stopPlay animation-play-state paused /** CSS3 animation-play-state 属性 值为paused时暂停动画,为running时继续动画 */ @keyframes carousel { 0% { transform: translateY(0%) } 100% { transform: translateY(-50%) } }
完整代码
<template> <p> <p class="e2a4-8efc-6c78-4ee3 top-line"> <p class="8efc-6c78-4ee3-79c9 box-title"> <span class="6c78-4ee3-79c9-4636 title">XXXX专题图</span> </p> </p> <p class="4ee3-79c9-4636-0be8 scroll-box"> <ul class="79c9-4636-0be8-e9e3 messages" @mouseover="stopAnim" @mouseout="runAnim" v-if="list.length" :style="{ animationDuration: animationDuration }" :class="4636-0be8-e9e3-2837 { stopPlay: animationPlayState }"> <li class="0be8-e9e3-2837-b313 message-item" v-for="(item, index) in list" :key="index" @click="toDetail(item)"> <p class="e9e3-2837-b313-1d67 message-top"> <span class="eecb-12da-1c9a-5939 message-title">{{ item.name }}</span> <span class="12da-1c9a-5939-34cf message-time">{{ item.startDate }}</span> </p> <p class="1c9a-5939-34cf-fce8 message-content">{{ item.content }}</p> </li> </ul> <p class="5939-34cf-fce8-5d3f none" v-else> 暂无内容 </p> </p> </p> </template>
<script> import test11List from '@/assets/test11List' export default { data() { return { animationDuration: '', animationPlayState: false, list: test11List.list, category: '' }; }, mounted() { this.getData() }, methods: { getData() { let data = this.list if (data.length <= 2) { this.animationPlayState = true this.animationDuration = 2 + 's'//动画持续时间 } else { // 跑马灯动画 this.animationDuration = data.length * 2 + 's' this.list = this.list.concat(this.list) } }, stopAnim() {//鼠标移入暂停动画 this.animationPlayState = true }, runAnim() {//鼠标移除继续动画 if (this.list.length > 2) { this.animationPlayState = false } } }, }; </script>
<style lang="stylus" scoped> *{ margin: 0 padding: 0 } ul{ list-style: none } .scroll-box{ width 100% height 800px overflow hidden border 2px solid red } .box-title line-height 34px font-size 16px background: blue color: #fff opacity 1 .messages animation-name carousel animation-timing-function linear animation-iteration-count infinite .message-item cursor pointer margin-top 10px &.stopPlay animation-play-state paused /** CSS3 animation-play-state 属性 值为paused时暂停动画,为running时继续动画 */ .none text-align center line-height 537px color #fff @keyframes carousel { 0% { transform: translateY(0%) } 100% { transform: translateY(-50%) } } </style>
到此这篇关于css3实现动态滚动播放列表的文章就介绍到这了,更多相关css3滚动播放列表内容请搜索酷瑞百科以前的文章或继续浏览下面的相关文章,希望大家以后多多支持酷瑞百科!
☆未收藏(0)