<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<style type="text/css">
#asd { width:480px; height:200px; background-image:url(image/3.jpg);}
</style>
<script type="text/jscript">
var but =["image/1.jpg","image/2.jpg","image/3.jpg","image/4.jpg","image/5.jpg","image/6.jpg"];
var z=0;
function fun()
{
if (z>but.length-1)
{z=0;}
document.getElementById("asd").style.backgroundImage ="url(but[z])";
z++
setTimeout("fun()",2000)
}
</script>
<body onload="fun()">
<div id="asd"></div>
</body>
</html>
我想做在一个层里面不停的变换图片的效果。 我是想用层的背景图片来做。 但是就是出不来。
大家帮我看看了。是不是="url(but[z])";写错了。 运行是一片空白呢!!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#asd { width:150px; height:99px;background-image:url("http://img5.nipic.com/2008-12-29/2008122995957609_1.jpg");}
</style>
<script type="text/javascript">
var but =["http://img1.nipic.com/2007-12-03/20071231357626_1.jpg","http://img5.nipic.com/2008-12-10/20081210153613409_1.jpg","http://img2.nipic.com/2008-03-24/200832410444719_1.jpg","http://img5.nipic.com/2008-12-24/20081224182838814_1.jpg","http://img2.nipic.com/2008-01-16/2008116122228195_1.jpg","http://img5.nipic.com/2008-12-29/2008122995957609_1.jpg"];
var z=0;
function fun(){
if(z == but.length){z=0;}
document.getElementById("asd").style.background = "url('"+but[z]+"')";
z++;
setTimeout("fun()",2000);
}
</script>
</head>
<body onload="fun()">
<div id="asd"></div>
</body>
</html>