利用JavaScript制作简单动画
时间:2007-02-17 来源:PHP爱好者
如果你需要改变动画播放速度,
比如每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 = "http://www.okasp.com/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="http://www.okasp.com/images/demo1.jpg" name="demo" width="100" height="100" alt="demo">
php爱好者 站 http://www.phpfans.net 网页制作|网站建设|数据采集.
比如每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 = "http://www.okasp.com/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="http://www.okasp.com/images/demo1.jpg" name="demo" width="100" height="100" alt="demo">
php爱好者 站 http://www.phpfans.net 网页制作|网站建设|数据采集.
相关阅读 更多 +