CSS animation动画实现无限滚动

1、animation属性

1.1、animation 属性是一个简写属性,用于设置六个动画属性

animation: name duration timing-function delay iteration-count direction;

animation-name 属性为 @keyframes 动画规定名称
animation-duration 属性定义动画完成一个周期所需要的时间,以秒或毫秒计。
animation-timing-function 规定动画的速度曲线。
animation-delay 属性定义动画何时开始
animation-iteration-count 属性定义动画的播放次数。
animation-direction 属性定义是否应该轮流反向播放动画。
1.2、暂停动画

animation-play-state: paused|running;

animation-play-state:paused; 指定暂停动画
animation-play-state:running; 指定正在运行的动画

2、无限滚动实现

<template>
  <div class="container">
    <div class="scroll_box">
      <ul>
        <li v-for="index in 6" :key="index">{{index}}</li>
      </ul>
      <ul>
        <li>1</li>
      </ul>
    </div>
  </div>
</template>

<style scoped lang="scss">
.container {
  .scroll_box {
    width: 200px;
    height: 200px;
    overflow: hidden;
    display: flex;
    margin: auto;
    border: 2px solid blue;
    ul {
      display: flex;
      padding: 0;
      margin: 0;
      position: relative;
      width: 1200px;
      animation: myScroll 5s linear infinite;
      li {
        list-style: none;
        width: 200px;
        height: 200px;
        text-align: center;
        line-height: 200px;
        font-size: 40px;
        color: red;
        border: 1px solid red;
        box-sizing: border-box;
        background: #1cdf27;
      }
    }
    &:hover {
      ul {
        animation-play-state: paused;
      }
    }

    @keyframes myScroll {
      from {
        left: 0px;
      }
      to {
        left: -1200px;
      }
    }
  }
}
</style>

3、效果展示

无限滚动

  • 10
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值