公告要实现横屏滚动,代码如下
<!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>
网友评论