首先这里声明一下,关于我测试浏览器的版本是chrome15.0.874.121 Firefox 8.01 IE9 IETester
下面的代码关于声明
1:获得滚动条的情况
代码如下:
function getScroll(){
var t, l, w, h;
if (document.documentElement && document.documentElement.scrollTop) {
t = document.documentElement.scrollTop;//滚动条的顶端
l = document.documentElement.scrollLeft;//滚动条的左端
w = document.documentElement.scrollWidth;//滚动条的宽度,也就是页面的宽度
h = document.documentElement.scrollHeight;//滚动条的高度
}
else
if (document.body) {
t = document.body.scrollTop;
l = document.body.scrollLeft;
w = document.body.scrollWidth;
h = document.body.scrollHeight;
}
return {
t: t,
l: l,
w: w,
h: h
};
}
2:获得视图浏览器的宽度高度
代码如下:
function getPageWidth(){
var pageWidth = window.innerWidth;
if (typeof pageWindth != "number") {
if (document.compatMode == "CSS1Compat") {
pageWidth = document.documentElement.clientWidth;
}
else {
pageWidth = document.body.clientWidth;
}
}
新闻热点
疑难解答
图片精选