Tuesday, June 2, 2009

Change Div Position Randomly on Home Page

Change Div position randomly on home page.here is simple example which display a div randomly on homepage within available width and hight.


CODE:
1 :  <Script Langauge="javscript">
2 :  var load=true;
3 :  var div_width=300;
4 :  var div_height=200;
5 :  var top=Math.floor(Math.random()*screen.availHeight - div_height)
6 :  var left=Math.floor(Math.random()*screen.availWidth - div_width)
7 :  document.write("<div id='pic_div' style='border:1px solid black;position:absolute;width:"+div_width+";height:"+div_height+";
8 :  text-align:center;left:0px;top:0px'>a</div>");
9 :  var d_obj=document.getElementById("pic_div");
10 :  d_obj.style.top=top;
11 :  d_obj.style.left=left;
12 :  </script>

1 comment: