顺便来一个纯 CSS 自卷动版,支援 IE Chrome Firefox。将滑鼠放在 div_parent 里面还会停止卷动喔。
<!DOCTYPE html><meta charset="UTF-8"/>
<style>
.div_parent { width: 1000px; border: 1px solid purple; overflow: hidden; white-space: nowrap; }
.div_child { width: 100px; height:300px; border: 1px solid green; display: inline-block; margin: 1ex; }
.div_child:first-child { animation: rollLeft linear 6s infinite; -webkit-animation: rollLeft linear 6s infinite; -moz-animation: rollLeft linear 6s infinite; }
.div_parent:hover .div_child:first-child { animation-play-state:paused; -webkit-animation-play-state:paused; -moz-animation-play-state:paused; }
@keyframes rollLeft { from { margin-left: 0; } to { margin-left: -1290px; } }
@-webkit-keyframes rollLeft { from { margin-left: 0; } to { margin-left: -1290px; } }
@-moz-keyframes rollLeft { from { margin-left: 0; } to { margin-left: -1290px; } }
</style>
<div class="div_parent">
<div class="div_child"></div><div class="div_child"></div><div class="div_child"></div><div class="div_child"></div>
<div class="div_child"></div><div class="div_child"></div><div class="div_child"></div><div class="div_child"></div>
<div class="div_child"></div><div class="div_child"></div><div class="div_child"></div><div class="div_child"></div>
<div class="div_child"></div><div class="div_child"></div><div class="div_child"></div><div class="div_child"></div>
<div class="div_child"></div><div class="div_child"></div><div class="div_child"></div><div class="div_child"></div>
</div>