這裡提供三種js函數,分頁是 獲取內容層內容原始尺寸 獲取捲軸的高度 獲取頁面實際大小的js代碼哦。
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "HTTP://www.w3.org/tr/xhtml1/dtd/ xhtml1-transitional.dtd">
<html xmlns="HTTP://www.w3.org/1999/xhtml">
<head>
<meta HTTP-equiv="content-type" content="text/html; charset=gb2312" />
<title>js獲取內容層內容原始尺寸 捲軸高度 頁面實際大小</title>
<script language="網頁特效">
獲取內容層內容原始尺寸
function getconsize(conid){
var conobj=document.getelementbyid(conid)
conobj.style.position = "absolute";
conobj.style.left=-1000+"px";
conobj.style.display="";
var arrayconsize=[conobj.offsetwidth,conobj.offsetheight]
conobj.style.display="none";
return arrayconsize;
}
function insertafter(newelement,targetelement){//插入
var parent = targetelement.parentnode;
if(parent.lastchild == targetelement){
parent.appendchild(newelement);
}
else{
parent.insertbefore(newelement,targetelement.nextsibling);
}
}
//獲取捲軸的高度
function getpagescroll(){
var yscroll;
if (self.pageyoffset) {
yscroll = self.pageyoffset;
} else if (document.documentelement && document.documentelement.scrolltop){
yscroll = document.documentelement.scrolltop;
} else if (document.body) {
yscroll = document.body.scrolltop;
}
arraypagescroll = new array('',yscroll)
return arraypagescroll;
}
//獲取頁面實際大小
function getpagesize(){
var xscroll,yscroll;
if (window.innerheight && window.scrollmaxy){
xscroll = document.body.scrollwidth;
yscroll = window.innerheight + window.scrollmaxy;
} else if (document.body.scrollheight > document.body.offsetheight){
sscroll = document.body.scrollwidth;
yscroll = document.body.scrollheight;
} else {
xscroll = document.body.offsetwidth;
yscroll = document.body.offsetheight;
}
var windowwidth,windowheight;
//var pageheight,pagewidth;
if (self.innerheight) {
windowwidth = self.innerwidth;
windowheight = self.innerheight;
} else if (document.documentelement && document.documentelement.clientheight) {
windowwidth = document.documentelement.clientwidth;
windowheight = document.documentelement.clientheight;
} else if (document.body) {
windowwidth = document.body.clientwidth;
windowheight = document.body.clientheight;
}
var pagewidth,pageheight
if(yscroll < windowheight){
pageheight = windowheight;
} else {
pageheight = yscroll;
}
if(xscroll < windowwidth) {
pagewidth = windowwidth;
} else {
pagewidth = xscroll;
}
arraypagesize = new array(pagewidth,pageheight,windowwidth,windowheight)
return arraypagesize;
}
</script>
</head>
<body>
</body>
</html>