求在屏幕上随机滚动图片的源代码

随机滚动图片,刚好碰到的,看看是不是符合你的要求,代码如下:
----------------------------------

 1<html>
 2<head>
 3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
 4<title>随机滚动图片</title>
 5</head>
 6<body>
 7<div id="img" style="position:absolute;z-index:99;">
 8<img border="0" onclick="pause_resume();" src="http://expert.csdn.net/images/csdn.gif"/>
 9</div>
10<script language="JavaScript">   
11<!-- Begin   
12var xPos = document.body.clientWidth-20;   
13var yPos = document.body.clientHeight/2;   
14var step = 1;   
15var delay = 5;   
16var height = 0;   
17var Hoffset = 0;   
18var Woffset = 0;   
19var yon = 0;   
20var xon = 0;   
21var pause = true;   
22var interval;   
23img.style.top = yPos;   
24function changePos() {   
25width = document.body.clientWidth;   
26height = document.body.clientHeight;   
27Hoffset = img.offsetHeight;   
28Woffset = img.offsetWidth;   
29img.style.left = xPos + document.body.scrollLeft;   
30img.style.top = yPos + document.body.scrollTop;   
31if (yon) {   
32yPos = yPos + step;   
33}else {   
34yPos = yPos - step;   
35}   
36if (yPos < 0) {   
37yon = 1;   
38yPos = 0;   
39}   
40if (yPos >= (height - Hoffset)) {   
41yon = 0;   
42yPos = (height - Hoffset);   
43}   
44if (xon) {   
45xPos = xPos + step;   
46}else {   
47xPos = xPos - step;   
48}   
49if (xPos < 0) {   
50xon = 1;   
51xPos = 0;   
52}   
53if (xPos >= (width - Woffset)) {   
54xon = 0;   
55xPos = (width - Woffset);   
56}   
57}   
58  
59function start() {   
60img.visibility = "visible";   
61interval = setInterval('changePos()', delay);   
62}   
63function pause_resume() {   
64if(pause) {   
65clearInterval(interval);   
66pause = false;   
67}else {   
68interval = setInterval('changePos()',delay);   
69pause = true;   
70}   
71}   
72start();   
73// End -->   
74</script>
75</body>
76</html>
Published At
Categories with Web编程
comments powered by Disqus