飘动的图片

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<BODY>
<img src="images/logo1.jpg" width="92" height="34" id="CSDN">
<img src="images/logo2.jpg" width="92" height="34" id="Wolf">
<img src="images/logo1.jpg" width="92" height="34" id="CSDN1">
<img src="images/logo2.jpg" width="92" height="34" id="Wolf1">
<SCRIPT LANGUAGE="JavaScript">
 

GoGoGo("CSDN");
GoGoGo("Wolf");

GoGoGo("CSDN1");
GoGoGo("Wolf1");

function GoGoGo(objName)
{
var img=document.getElementById(objName) ;
img.style.position="absolute";
img.style.left=parseInt(window.screen.availWidth*Math.random()) + "px";
img.style.top=parseInt(window.screen.availHeight*Math.random()) + "px";
img.setAttribute("xDir",1);//&para;¨&Ograve;&aring;&iquest;&ordf;&Ecirc;&frac14;x&micro;&Auml;·&frac12;&Iuml;ò
img.setAttribute("yDir",1);//&para;¨&Ograve;&aring;&iquest;&ordf;&Ecirc;&frac14;x&micro;&Auml;·&frac12;&Iuml;ò
window.setInterval("randPosition(" + objName + ")","10","JavaScript");
}

function randPosition(obj)
{
var x=parseInt(obj.style.left);
if(x>=window.screen.availWidth-obj.width-20)
obj.setAttribute("xDir",-1);
if(x<=0)
obj.setAttribute("xDir",1);
x+=parseInt(obj.getAttribute("xDir"));

var y=parseInt(obj.style.top);
if(y>=window.screen.availHeight-obj.height-100)
obj.setAttribute("yDir",-1);
if(y<=0)
obj.setAttribute("yDir",1);
y+=parseInt(obj.getAttribute("yDir"));
 
obj.style.left=x +"px";
obj.style.top =y +"px";

}
</SCRIPT>
</BODY>
</HTML>

你可能感兴趣的:(飘动的图片)