背景
使用JavaScript实现轮播图效果。
实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>轮播图</title>
<style>
img{
width: 50%;
}
</style>
</head>
<body>
<img id = "pic" src="pic0.jpg">
<script>
var number = 0;
function fun(){
number ++;
if (number === 3){
number = 0;
}
pic.src = "pic" +number+ ".jpg"; //需确保轮播图文件在当前项目中
}
setInterval(fun, 2000);
</script>
</body>
</html>