<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>setInterval使用方法</title>
<style type="text/css">
img {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<script type="text/javascript">
window.addEventListener('load', function() {
var pic = document.querySelector('img');
var flag = 1;
setInterval(function() {
console.log('打印');
if(flag < 4) {
pic.src = "images/" + flag + ".jpg";
flag++;
} else {
flag = 1;
pic.src = "images/" + flag + ".jpg";
}
}, 2000);
})
</script>
<img src="images/1.jpg" />
</body>
</html>
循环播放图片
最新推荐文章于 2022-02-27 11:02:54 发布