统一用它吧: document.documentElement.scrollTop
解决方案 »
- 表格明细赋值问题
- arguments 的问题
- 我怎么学习JavaScript好呢....
- HELP!! How to decode encoded Polylines?
- 颜色格式问题("#000000")
- 自做的控件有一方法,返回VARIANT变量类型,在javascript中如何能使用该VARIANT数据?
- 在JavaScript中提交Form怎么写?
- 如何把<select></select>中的值传到父窗口中去?
- document.write 的迷惑
- javascript的这段代码看不懂,myFunction()和forEach()
- 哪位记得如何禁用IE的右键菜单功能?小弟一下想不起来了!
- 【高手解迷】“单击 + 图片重载”经常引发光标定义失效
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<html>
<head>
<title>++</title>
</head>
<body onclick="cc()">
<script language="javascript" type="text/javascript">
function cc(){
alert(document.documentElement.scrollTop);
}
</script>
<table>
<tr>
<td height="6000"></td>
</tr>
</table>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
改成这样
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">这是IE5与IE6的区别:
var scrollPos;
if (typeof window.pageYOffset != 'undefined') {
scrollPos = window.pageYOffset;
}
else if (typeof document.compatMode != 'undefined' &&
document.compatMode != 'BackCompat') {
scrollPos = document.documentElement.scrollTop;
}
else if (typeof document.body != 'undefined') {
scrollPos = document.body.scrollTop;
}
alert(scrollPos);还有改好方法就是
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"' target=_new>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
//Page
getBodyWidth : function()
{
return document.documentElement.clientWidth || document.body.clientWidth || 0;
},
getBodyHeight : function()
{
return document.documentElement.clientHeight || document.body.clientHeight || 0;
},
getBodyLeft : function()
{
return document.documentElement.scrollLeft || document.body.scrollLeft || 0;
},
getBodyTop : function()
{
return document.documentElement.scrollTop || document.body.scrollTop || 0;
},
getBody : function()
{
return {
width : this.getBodyWidth(),
height : this.getBodyHeight(),
left : this.getBodyLeft(),
top : this.getBodyTop()
};
},
getScreenWidth : function()
{
return window.screen.width;
},
getScreenHeight : function()
{
return window.screen.height;
}, //Element
getElementWidth : function(o)
{
(typeof o == "string") ? o = $(o) : "";
return o.offsetWidth;
},
getElementHeight : function(o)
{
(typeof o == "string") ? o = $(o) : "";
return o.offsetHeight;
},
getElementLeft : function(o)
{
if (o == null)
{
return 0;
} (typeof o == "string") ? o = $(o) : "";
return (o.offsetLeft + this.getElementLeft(o.offsetParent));
},
getElementTop : function(o)
{
if (o == null)
{
return 0;
} (typeof o == "string") ? o = $(o) : "";
return (o.offsetTop + this.getElementTop(o.offsetParent));
},
getElement : function(o)
{
return {
width : this.getElementWidth(o),
height : this.getElementHeight(o),
left : this.getElementLeft(o),
top : this.getElementTop(o)
};
},
getBorderLeft : function(o)
{
return parseInt(this.getCurrentStyle(o, "borderLeftWidth"));
},
getBorderTop : function(o)
{
return parseInt(this.getCurrentStyle(o, "borderTopWidth"));
},
getBorderRight : function(o)
{
return parseInt(this.getCurrentStyle(o, "borderRightWidth"));
},
getBorderBottom : function(o)
{
return parseInt(this.getCurrentStyle(o, "borderBottomWidth"));
},
getBorder : function(o)
{
return {
left : this.getBorderLeft(o),
top : this.getBorderTop(o),
right : this.getBorderRight(o),
bottom : this.getBorderBottom(o)
};
}, //Style
getCurrentStyle : function(o, s)
{
(typeof o == "string") ? o = $(o) : ""; if (o.currentStyle)
{
return o.currentStyle[s];
}
else if (document.defaultView.getComputedStyle)
{
return document.defaultView.getComputedStyle(o, '').getPropertyValue(s.replace(/([A-Z])/g, '-$1').toLowerCase());
}
else
{
return o.style[s];
}
},
setStyle : function(o, s, v)
{
(typeof o == "string") ? o = $(o) : ""; if (Browser.moz && s == "cursor" && v == "hand")
{
v = "pointer";
} o.style[s] = v;
}
};