js 광고 부유 효과 실현 사례


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<style type="text/css">
div{
position:absolute;
}
</style>
</head>
<body>
<div id="floatdiv">
<img src="1.jpg" height="100px" width="200px">

</div>
</body>
</html>
<script language="javascript" type="text/javascript">
/*
window ,

 1、 div, , (0,0)
 2、
 3、 div
  1)div ,
*/
// div

var img=document.getElementById("floatdiv");
// div
var x=0,y=0;
// div
var xSpeed=2,ySpeed=1;
//
var w=document.body.clientWidth-200,h=document.body.clientHeight-100;
function floatdiv(){
 // , ;
 if(x>w||x<0) xSpeed= -xSpeed;
 if(y>h||y<0) ySpeed= -ySpeed;

 x+=xSpeed;
 y+=ySpeed;

 // , +
 img.style.top=y+"px";
 img.style.left=x+"px";
setTimeout("floatdiv()",10);
}
floatdiv();
</script>

좋은 웹페이지 즐겨찾기