<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>无限循环滚动
</title>
<style>
* {
margin: 0;
padding: 0;
}
div {
width: 600px;
height: 161px;
border: 1px solid #000;
margin: 100px auto;
overflow: hidden;
}
ul {
list-style: none;
width: 1800px;
height: 161px;
background: #000;
}
ul > li {
float: left;
}
</style>
<script src="./js/jquery-3.5.1.js"></script>
<script>
$(function () {
let offset = 0
var timer
function autoPlay() {
timer = setInterval(function () {
offset -= 10
if (offset <= -1200) {
offset = 0
}
$("ul").css("marginLeft", offset + "px");
}, 100)
}
autoPlay()
$("li").hover(function () {
clearInterval(timer)
$(this).siblings().fadeTo(100, 0.3)
$(this).fadeTo(100, 1)
}, function () {
autoPlay()
$("li").fadeTo(100, 1)
})
})
</script>
</head>
<body>
<div>
<ul>
<li><img src="images/scrollFirst.png" alt=""></li>
<li><img src="images/scrollSecond.png" alt=""></li>
<li><img src="images/scrollThird.png" alt=""></li>
<li><img src="images/scrollForth.png" alt=""></li>
<li><img src="images/scrollFirst.png" alt=""></li>
<li><img src="images/scrollSecond.png" alt=""></li>
</ul>
</div>
</body>
</html>
转载请注明原文地址:https://tech.qufami.com/read-24353.html