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

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

作者: lvyweb | 来源:发表于2023-04-17 11:21 被阅读0次

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

<!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>

相关文章

网友评论

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

      本文链接:https://www.haomeiwen.com/subject/oeqcjdtx.html