HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
来源:互联网 发布:mysql不允许远程连接 编辑:程序博客网 时间:2024/03/28 21:56
scrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:获取对象的滚动宽度
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
offsetLeft:获取对象相对于版面或由 offsetParent 属性指定的父坐标的计算左侧位置
offsetTop:获取对象相对于版面或由 offsetTop 属性指定的父坐标的计算顶端位置
event.clientX 相对文档的水平座标
event.clientY 相对文档的垂直座标
event.offsetX 相对容器的水平坐标
event.offsetY 相对容器的垂直坐标
document.documentElement.scrollTop 垂直方向滚动的值
event.clientX+document.documentElement.scrollTop 相对文档的水平座标+垂直方向滚动的量
以上主要指IE之中,FireFox差异如下:
IE6.0、FF1.06+:
clientWidth = width + padding
clientHeight = height + padding
offsetWidth = width + padding + border
offsetHeight = height + padding + border
IE5.0/5.5:
clientWidth = width - border
clientHeight = height - border
offsetWidth = width
offsetHeight = height
(需要提一下:CSS中的margin属性,与clientWidth、offsetWidth、clientHeight、offsetHeight均无关)
实例
1。
offsetLeft:Html元素相对于自己的offsetParent元素的位置
scrollLeft:返回和设置当前横向滚动务的坐标值
<input type="button" value="点一下" onclick="move()">
<div id="d" style="background-color:#ff9966; position:absolute; left:170px; top:100px;width:300;height:300;overflow:scroll"
onclick="alert('offsetLeft:'+this.offsetLeft)">
<div style="height:600;width:600" onclick="alert('offsetLeft:'+this.offsetLeft)"></div>
</div>
<script language="javascript">
function move()
{
var d=document.getElementById("d")
a=eval(20)
d.scrollLeft+=a
}
</script>
保存为网页,运行一下,点按钮,滚动条移动
点击div,先弹出b相对于a的位置,再弹出a相对于窗口的位置
-------------------------------------------------------------------------------------------------------------------------------------------------
2。
一个函数在鼠标移到图片上调用,显示隐藏层并将图片载入到层中;
另一个函数在鼠标移出图片上调用,清空层的内容并隐藏层。使用时需将"this.src"改为产品大图地址。
以下是引用片段:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS函数实现鼠标指向后带图片的提示效果</title>
<script language="javascript">
function showPic(sUrl){
var x,y;
x = event.clientX;
y = event.clientY;
document.getElementById("Layer1").style.left = x;
document.getElementById("Layer1").style.top = y;
document.getElementById("Layer1").innerHTML = "<img src=/"" + sUrl + "/">";
document.getElementById("Layer1").style.display = "block";
}
function hiddenPic(){
document.getElementById("Layer1").innerHTML = "";
document.getElementById("Layer1").style.display = "none";
}
</script>
</head>
<body>
<div id="Layer1" style="display:none;position:absolute;z-index:1;"></div>
<img src="/images/logo.gif" onmouseout="hiddenPic();" onmousemove="showPic(this.src);" />
<p></p>
<img src="/img/200406301.jpg" onmouseout="hiddenPic();" onmousemove="showPic(this.src);" />
</body>
</html>
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解 .
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- 完全详解HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth
- 公司是技术人员还是市场人员更重要?
- 在login.sql文件中设置sql*plus的环境(摘自《Oracle编程艺术》)
- 智能设备 C#调用MFC DLL 传参值为汉字的解决方案 CString转存 unsigned char数组
- 北京信息工程学院、北京信息科技大学 软件工程课程设计全部代码,希望对北信的下一代有用!
- VC中使用SCRIPT 正则写的LRC歌词分析类
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- 摩羯
- 运算符++的奥秘
- 程序员
- 加密狗
- 60秒出口才
- 程序员真实写真35岁前成功的12条黄金法则.doc
- 好工作要坚持.doc
- 经常问到的技术面试题.doc