CSS实现文字横向滚动,鼠标移入暂停移出继续

公告要实现横屏滚动,代码如下

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
      div{
        width:300px;
        border:1px solid #000;
        overflow:hidden;
        white-space: nowrap;
      }
p{
animation:wordsLoop 10s infinite;
}
@keyframes wordsLoop{
  0%{transform:translateX(100%);}
   100%{transform:translateX(-100%);}
}
.roll-box:hover {
    /* 设置动画是否暂停 paused暂停*/
    animation: wordsLoop 10s  infinite paused;
}
</style>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
</head>
<body>
<div>
    <p class="roll-box">这是段横向滚动的文字666666这是段横向滚动的文字这是段横向滚动的文字这是段横向滚动的文字这是段横向滚动的文字这是段横向滚动的文字这是段横向滚动的文字99999</p>
</div>

<script>
    var _strLength = $(".roll-box").text().length;
    var _second = _strLength / 5;
    $(".roll-box").css({
        "animation-duration": _second + "s"
    })

</script>
</body>
</html>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容