轮播图案例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-3.5.1.min.js"></script>
<script type="text/javascript">
var i = 1;
var t;
$(function() {
toggerImg();
/*$("span").click(function() {
});*/
$("span").mouseenter(function(){
i = $(this).text();
clearTimeout(t);//清楚定时器
toggerImg();
});
});
function toggerImg(){
$("img").attr("src", "img/" + i + ".jpg");
if(i >= 5) {
i = 0;
}
i++;
t = setTimeout("toggerImg()",2000);
}
</script>
<style type="text/css">
img {
width: 650px;
height: 400px;
border: 1px solid black;
}
</style>
</head>
<body>
<div>
<img src="img/1.jpg" />
</div>
<!--<span>切换</span>-->
<span>1</span> <span>2</span> <span>3</span> <span>4</span> <span>5</span>
</body>
</html>
效果演示:
http://127.0.0.1:8020/jquery_02/index2.html?__hbt=1606195201311