首页 > 代码库 > 图片定时自动播放

图片定时自动播放

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片定时自动播放</title>
<script type="text/javascript">
var banner = ["images/banner.jpg","images/banner1.jpg","images/banner2.jpg"];
var number = 0;
function sun() {
setInterval(cycle,2000);
}
function cycle() {
number++;
if(number == banner.length) number = 0;
document.getElementById("banner").src = http://www.mamicode.com/banner[number];
}
</script>
</head>

<body onl oad="sun();">
<img id="banner" src="http://www.mamicode.com/images/banner.jpg" />
</body>
</html>

图片定时自动播放