doc.documentElement.scrollLeft||doc.body.scrollLeft//这个是为了兼容FF和IEwnd = wnd || window; //这个也一样
解决方案 »
- 这个论坛里发帖的时候那个选择论坛-子论坛的三个级联的框框是怎么实现的?
- 一小段代码。请大家帮忙看看
- 100分求解一个兼容w3c标准的问题
- 让文本域里边按"Enter"键变成换行键
- 急为什么我用showModalDialog打开窗口TEST1.ASP,test1.asp自己再showModalDialog自己,会出来新窗口,加了<base target='_self'> ,还会
- 如何用jquery做下拉刷新的效果??很纠结jquery能不能做出来!!!
- 高手近来帮我看看???
- 怎么样实现两个select 互相传值?
- 谁知道如何获取鼠标点击处控件的id
- 怎样控制当前窗口的最大化和最小化?
- 关于菜单层的显示与隐藏 高手请进
- 小问题多送分,先来先得
既然都取的到跟元素 干嘛还要这个doc.body.scrollLeft了 不明白。
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Rank's HTML document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="ImageToolbar" content="no" />
<style type="text/css" title="default" media="screen">
/*<![CDATA[*/
/*]]>*/
</style>
</head>
<body>
<div id="demo">鼠标按下,并拖动,可看到参数 <a href="http://www.never-online.net">never-online, rank</a></div>
<script type="text/javascript">
//<![CDATA[
function getDocRect (wnd) {
wnd = wnd || window;//判断对象,是window还是当前object
doc = wnd.document;
return {
left :doc.documentElement.scrollLeft||doc.body.scrollLeft||wnd.pageXOffset||wnd.scrollX||0, //因为调用SetCapture后你鼠标可以跑到浏览器外面
top :doc.documentElement.scrollTop||doc.body.scrollTop||wnd.pageYOffset||wnd.scrollY||0, //。。
width :doc.documentElement.clientWidth||doc.body.clientWidth||wnd.innerWidth||doc.width||0,//。
height :doc.documentElement.clientHeight||doc.body.clientHeight||wnd.innerHeight||doc.height||0 //。
}
};
var c = 0; var b = false;
var d = document.getElementById("demo");
document.onmousedown = function () {
d.innerHTML = 'down'; b = true;
if (d.setCapture) d.setCapture();//调用SetCapture后,即使鼠标移动出客户区,你也可以接受到鼠标消息。下面用GetCapture可以知道当前哪个窗口调用了SetCapture document.onmousemove = function (evt) {
if (!b) return;
evt = evt || window.event; //为了兼容FF
var x, y;
var rect = getDocRect();//获取哪个窗口调用了SetCapture
x = evt.clientX;
y = evt.clientY;
window.defaultStatus = 'x:' +x+ ',y:' +y+ ' -- w:' +rect.width+ ',h:' +rect.height+ ',l:' +rect.left+ ',t:' +rect.top;
if (x>=rect.width || y>=rect.height
|| 0>=x || 0>=y) {
return;
}
d.innerHTML = c++;
};
document.onmouseup = function () {
if (!b) return;
if (document.releaseCapture) document.releaseCapture();//松开鼠标ReleaseCapture释放setCapture。
document.onmousemove = null;
d.innerHTML = 'up';
b = false;
}
}
//]]>
</script>
</body>
</html>
1.doc.documentElement.scrollLeft||doc.body.scrollLeft
ie ff下 通过doc.documentElement.scrollLeft都是可以去到根元素html的
所以了我就觉得后面的doc.body.scrollLeft是不是多余了 (这2个东西的大小是不是相等的??? - -!我也不清楚)2.wnd.pageYOffset 这个是啥意思(我可是先baidu google了的,但是没找到明确的解释)3。wnd.innerWidth又是什么意思 (这个没查)4.为什么最后要有一个0 (貌似按3楼的解释可以理解的通)