利用JAVASCRIPT制作简单动画
发布时间:2006-10-14 3:08:04   收集提供:gaoqian
  如果你需要改变动画播放速度,
比如每5秒换一张图片
改变setTimeout("imgturn('" +numb+ "')", 1000)中的1000为5000

<html>
<head>
<title></title>

<script language="javascript">
<!--
//请先准备几张JPG图片格式的,名字是demo1.jpg,demo2.jpg,demo3.jpg
if (document.images) {
demo1 = new Image();
demo1.src = "../../images/demo1.jpg";

demo2 = new Image();
demo2.src = "../../images/demo2.jpg";

demo3 = new Image();
demo3.src = "../../images/demo3.jpg";
}

function timeimgs(numb) {
thetimer = setTimeout("imgturn('" +numb+ "')", 1000);
}

function imgturn(numb) {
if (document.images) {

if (numb == "3") {
document["demo"].src = eval("demo3.src");
timeimgs('1');
}

else { document["demo"].src = eval("demo" + numb + ".src");

timeimgs(numb = ++numb);
}
}
}

// -->
</script>

</head>
<body onload="timeimgs('2');">

<img src="../../images/demo1.jpg" name="demo" width="100" height="100" alt="demo">
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50