公告要實(shí)現(xiàn)橫屏滾動(dòng)源梭,代碼如下
<!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 {
/* 設(shè)置動(dòng)畫(huà)是否暫停 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">這是段橫向滾動(dòng)的文字666666這是段橫向滾動(dòng)的文字這是段橫向滾動(dòng)的文字這是段橫向滾動(dòng)的文字這是段橫向滾動(dòng)的文字這是段橫向滾動(dòng)的文字這是段橫向滾動(dòng)的文字99999</p>
</div>
<script>
var _strLength = $(".roll-box").text().length;
var _second = _strLength / 5;
$(".roll-box").css({
"animation-duration": _second + "s"
})
</script>
</body>
</html>