获取页面滚动高度

2012年4月2日 发表评论 阅读评论

from http://www.xyhot.com/article.asp?id=168

<!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" lang="gb2312">
<head>
<head>
<title> 代码实例:获取页面滚动高度 scrollTop(For: IE5.0+、Firefox1.06+ …) </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="author" content="枫岩,CnLei.y.l@gmail.com">
<meta name="copyright" content="http://www.cnlei.com" />
<meta name="description" content="获取页面滚动高度 scrollTop(For: IE5.0+、Firefox1.06+ …)" />
<script type="text/javascript">
var w3c=(document.getElementById)? true: false;
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));

function IeTrueBody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function GetScrollTop(){
return ie ? IeTrueBody().scrollTop : window.pageYOffset;
}
</script>
</head>
<body>
<p><a href="javascript:alert(GetScrollTop());">GetScrollTop()</a></p>
<p style="height:250px;"> </p>
<p><a href="javascript:alert(GetScrollTop());">GetScrollTop()</a></p>
<p style="height:250px;"> </p>
<p><a href="javascript:alert(GetScrollTop());">GetScrollTop()</a></p>
<p style="height:250px;"> </p>
</body>
</html>

liz

function show_window(sid)
{

var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
var IeTrueBody = (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
var scrollHeight = ie ? IeTrueBody.scrollTop : window.pageYOffset;
var e = event;
var curWindowHeight = window.screen.availHeight – window.screenTop;
var curWindowWidth = window.screen.availWidth;
var oldDivHeight = parseInt(show_msg.style.height.substr(0,3));
var oldDivWidth = parseInt(show_msg.style.width.substr(0,3));
var cursorX = e.x;
var cursorY = e.y;
var newDivTop = 0;
var newDivLeft = 0;
if((curWindowHeight – cursorY) > oldDivHeight) newDivTop = cursorY + scrollHeight;
else newDivTop = cursorY – oldDivHeight + scrollHeight -5;
if(2*(curWindowWidth – cursorX)/3 > oldDivWidth) newDivLeft = cursorX;
else newDivLeft = cursorX – oldDivWidth;
show_msg.style.top = newDivTop;
show_msg.style.left = newDivLeft – 30;
show_msg.innerHTML = eval("desc"+sid).innerHTML;
show_msg.style.display = ”;
}
function hidden_window()
{
show_msg.style.display = ‘none’;
}


转载请注明来自:[MSN Spaces]http://msn.shandian.biz/360.html

  1. 本文目前尚无任何评论.