4

纯CSS实现无限循环轮播

 9 months ago
source link: https://scarsu.com/infinite_scroll_by_css/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

纯CSS实现无限循环轮播

无JS代码实现无限循环轮播、鼠标悬浮时暂停动画、鼠标移出时继续动画

2022/4/23
1
原理

demo代码

<div class="wrap">
  <div class="slide-dom">
    <div class="itemA">A</div>
    <div class="itemB">B</div>
    <div class="itemA">A</div>
    <div class="itemB">B</div>
  </div>
</div>
@keyframes infinite-slide {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}
.wrap {
  overflow-x: visible;
  background: #eee;
  width: 200px;
  height: 300px;
  margin: 0 auto;
  padding: 100px 0;
}
.slide-dom {
  width: max-content;
  animation: infinite-slide 10s linear infinite;
}
/* 鼠标悬浮时暂停动画 */
.slide-dom:hover {
  animation-play-state: paused;
}
.itemA {
  display: inline-block;
  width: 200px;
  height: 100px;
  background: pink;
}
.itemB {
  display: inline-block;
  width: 200px;
  height: 100px;
  background: yellow;
}

demo在线地址

preview
上次更新: 2022/4/23

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK