2014年1月2日星期四

jsp page on document.body.scrollTop and document.documentElement.scrollTop difference. . . . . . . . . . . .

I heard document.body.scrollTop always 0 , but I tried not 0, Irony document.documentElement.scrollTop is 0 , God horse situation ?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
function test()
{
document.getElementById("test").innerHTML = document.body.scrollTop;
document.getElementById("test1").innerHTML = document.documentElement.scrollTop;
}
</script>
</head>
<body>
<div style="height:2000px;"></div>
<div id="test"></div>
<div id="test1"></div>
<input type="button" onclick="test()"/>
</body>
</html>

------ Solution ------------------------------------- -------
first document.body.scrollTop should scroll to the top of the distance to the top of the page . Second , I also have been 0
------ Solution ------------------------------- -------------
http://blog.csdn.net/lploveme/article/details/7011174
------ Solution ------- -------------------------------------

html elements should also be considered documentElement
0 can not say useless ah , but also the objective reality of the reaction .
------ Solution ---------------------------------------- ----
main floor, believe in yourself heard all proved too tricky
------ For reference only -------------- -------------------------
I rely on . . Wood someone know?
------ For reference only -------------------------------------- -
wood was ah. . . .
------ For reference only -------------------------------------- -
question now is document.documentElement.scrollTop always 0 , that thing you want to dim . .
------ For reference only -------------------------------------- -

Taiwan enterprises ? I have not read the words . .
------ For reference only -------------------------------------- -
these two methods are to get the scroll bar to scroll the distance, but document.body.scrolltop will scrolltop lapse web standards manipulation , document.documentElement.scrolltop must exist before changing the value of the rolling elements or is 0
------ For reference only --------------------------------------- < br> var advTop;
var advLeft;
var advObj;

/ * floating ad code * /
function init ()
{
advObj = document.getElementById ("apDiv1");
if (advObj.currentStyle) / / IE
{
advTop = parseInt (advObj.currentStyle.top) ;/ / currentStyle specified object format and style
advLeft = parseInt (advObj.currentStyle.left);

}
else / / FF
{
advTop = parseInt (document.defaultView.getComputedStyle (advObj, null) top.);
advLeft = parseInt (document.defaultView.getComputedStyle (advObj, null) left.);
/ * var style = document.defaultView.getComputedStyle (elem1, null);
/ / The above is equivalent to :
var elem1 = document.getElementById ("elemId");
var style = window.getComputedStyle (elem1, null); * /
}
}
function move ()
{
/ / var top = document.documentElement.scrollTop | | document.body.scrollTop;
/ / var top = document.documentElement.scrollTop document.documentElement.scrollTop?:
if (document.body.scrollTop> document.documentElement.scrollTop) {/ / page is to high volume : document.body.scrollTop;
advObj.style.top = advTop + parseInt (document.body.scrollTop) + "px";
}
else {
advObj.style.top = advTop + parseInt (document.documentElement.scrollTop) + "px";
}

}
window.onload = init;
window.onscroll = move;

没有评论:

发表评论