Mike 发表于 2021-7-8 09:33:29

前端基础 - HTML定时轮播图片

  定时轮播图片  效果图(图片一直轮流切换):

  代码:
<!DOCTYPE html>
<html>
<head>

<meta charset="UTF-8">

<title>轮播图测试</title>

<script>

window.onload = function(){
window.setInterval(changePic,1000);
}

var num = 1;

function changePic(){
++num;
if(num == 4){
num = 1;
}
var imgElement = document.getElementById("img1");
imgElement.src = "img/"+num+".jpg";
}

</script>

</head>
<body>
<img id="img1" src="img/1.jpg" width="100%" />

</body>
</html>



  
文档来源:51CTO技术博客https://blog.51cto.com/u_15294985/2999154
页: [1]
查看完整版本: 前端基础 - HTML定时轮播图片