posts - 0, comments - 77, trackbacks - 0, articles - 356
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

javascript固定div位置在页面中的位置

Posted on 2007-09-12 15:03 semovy 阅读(7131) 评论(2)  编辑  收藏 所属分类: JavaScript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<HEAD>
<TITLE>AAAAAAAA</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html" charset="UTF-8">
</HEAD>
<style>
<!--
.div{
position: absolute;
border: 2px solid red;
background-color: #EFEFEF;
line-height:90px;
font-size:12px;
z-index:1000;
}
-->
</style>
<BODY>
<div id="Javascript.Div1" class="div" style="width: 240px; height:90px" align="center">正中...</div>
<SCRIPT LANGUAGE="JavaScript">
function sc1(){
document.getElementById("Javascript.Div1").style.top=
   document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById("Javascript.Div1").offsetHeight)/2
document.getElementById("Javascript.Div1").style.left=
   document.documentElement.scrollLeft+(document.documentElement.clientWidth-document.getElementById("Javascript.Div1").offsetWidth)/2;
}
</SCRIPT>


<div id="Javascript.Div2" class="div" style="width: 240px; height:90px;" align="center">左上...</div>
<SCRIPT LANGUAGE="JavaScript">
function sc2(){
document.getElementById("Javascript.Div2").style.top=document.documentElement.scrollTop
document.getElementById("Javascript.Div2").style.left=document.documentElement.scrollLeft;
}
</SCRIPT>

<div id="Javascript.Div3" class="div" style="width: 240px; height:90px;" align="center">左下...</div>
<SCRIPT LANGUAGE="JavaScript">
function sc3(){
document.getElementById("Javascript.Div3").style.top=
    document.documentElement.scrollTop+document.documentElement.clientHeight-document.getElementById("Javascript.Div3").offsetHeight;
document.getElementById("Javascript.Div3").style.left=document.documentElement.scrollLeft;
}
</SCRIPT>

<div id="Javascript.Div4" class="div" style="width: 240px; height:90px;" align="center">右上...</div>
<SCRIPT LANGUAGE="JavaScript">
function sc4(){
document.getElementById("Javascript.Div4").style.top=document.documentElement.scrollTop;
document.getElementById("Javascript.Div4").style.left=
    document.documentElement.scrollLeft+document.documentElement.clientWidth-document.getElementById("Javascript.Div4").offsetWidth;
}
</SCRIPT>

<div id="Javascript.Div5" class="div" style="width: 240px; height:90px;" align="center">右下...</div>
<SCRIPT LANGUAGE="JavaScript">
function sc5(){

document.getElementById("Javascript.Div5").style.top=
    document.documentElement.scrollTop+document.documentElement.clientHeight-document.getElementById("Javascript.Div5").offsetHeight;
document.getElementById("Javascript.Div5").style.left=
    document.documentElement.scrollLeft+document.documentElement.clientWidth-document.getElementById("Javascript.Div5").offsetWidth;;
}
</SCRIPT>


<SCRIPT LANGUAGE="JavaScript">
<!--
function scall(){
sc1();sc2();sc3();sc4();sc5();
}
window.onscroll=scall;
window.onresize=scall;
window.onload=scall;
//-->
</SCRIPT>
<div style="position: absolute; top: 0; left: 0; width: 10000px; height: 4000px;"></div>
</BODY>
</HTML>

 


评论

# re: javascript固定div位置在页面中的位置  回复  更多评论   

2008-08-30 10:35 by Smalllong
Firefox下好像不行啊

# re: javascript固定div位置在页面中的位置  回复  更多评论   

2009-08-06 16:20 by zjz
google也不行的

只有注册用户登录后才能发表评论。


网站导航: