<html>
<head>
<title>changePage</title>
</head>
<body>
<table id="pic" cellpadding="0" cellspacing="0" border="1" width="200" height="100" bordercolor="red">
<tr>
<td>picture chanage!</td>
</tr>
</table>
<script type="text/javascript">
<!--
window.onload=function()
{
changePicture();
}
var time=0;
function changePicture(){
time++;
document.getElementById('pic').background="images/"+time+".jpg";
if(time==3)
changePicture1();
else
setTimeout(changePicture,500);
}
function changePicture1(){
document.getElementById('pic').background="images/"+time+".jpg";
time--;
if(time==0)
changePicture();
else
setTimeout(changePicture1,10000); //设定时间
}
-->
</script>
</body>
</html>
本文介绍了一个简单的网页图片自动切换效果实现方法。通过JavaScript定时更改图片背景,实现了图片的正向和反向切换,并且设置了不同的切换间隔时间。
1007

被折叠的 条评论
为什么被折叠?



