标题:
[
JavaScript
]
图片循环显示
[打印本页]
作者:
shillan
时间:
2006-11-14 23:23
标题:
图片循环显示
1.把<body>中内容改为:
<body onload="rotateimage('rimage')">
2在head区域中加入如下代码
<script language="javascript"> <!-- begin var interval = 2.5; // delay between rotating images (in seconds) var random_display = 1; // 0 = no, 1 = yes interval *= 1000; var image_index = 0; image_list = new array(); image_list[image_index++] = new imageitem("1.jpg"); image_list[image_index++] = new imageitem("2.jpg"); image_list[image_index++] = new imageitem("3.jpg"); image_list[image_index++] = new imageitem("4.jpg"); var number_of_image = image_list.length; function imageitem(image_location) { this.image_item = new image(); this.image_item.src = image_location; } function get_imageitemlocation(imageobj) { return(imageobj.image_item.src) } function generate(x, y) { var range = y - x + 1; return math.floor(math.random() * range) + x; } function getnextimage() { if (random_display) { image_index = generate(0, number_of_image-1); } else { image_index = (image_index+1) % number_of_image; } var new_image = get_imageitemlocation(image_list[image_index]); return(new_image); } function rotateimage(place) { var new_image = getnextimage(); document[place].src = new_image; var recur_call = "rotateimage('"+place+"')"; settimeout(recur_call, interval); } // end --> </script>
加入如下代码到body区域
<img name="rimage" src="1.jpg">
欢迎光临 逐梦论坛 (http://temp2023.zhumeng.org/)
Powered by Discuz! 7.2