*{ margin:0; padding:0}
div {padding: 40px 50px;}
#div1 {background: red;}
#div2 {background: green; }
#div3 {background: orange;} <div id="div1">
<div id="div2">
<div id="div3"></div>
</div>
</div> <script>
window.onload = function() {
var oDiv3 = document.getElementById('div3');
alert( oDiv3.offsetTop );
}
</script>

offsetTop 
div3无定位父级则显示为到body的距离
火狐,谷歌,360,opera:80
ie7-11:80
offsetLeft

div3无定位父级则显示为到body的距离
火狐,谷歌,360,opera:100
ie7-11:100
 
*{ margin:0; padding:0}
div {padding: 40px 50px;}
#div1 {background: red;}
#div2 {background: green;position:relative }
#div3 {background: orange;} <div id="div1">
<div id="div2">
<div id="div3"></div>
</div>
</div> <script>
window.onload = function() {
var oDiv3 = document.getElementById('div3');
alert( oDiv3.offsetTop );
}
</script>
offsetTop
div3有定位父级则显示为到div2(父级)的距离
火狐,谷歌,360,opera:40
ie8-11:40
ie7:80
offsetLeft
div3有定位父级则显示为到div2(父级)的距离
火狐,谷歌,360,opera:40
ie8-11:50
ie7:100
如果自己没有定位,那么offsetLeft[Top]是到body的距离
 
*{ margin:0; padding:0}
div {padding: 40px 50px;}
#div1 {background: red;}
#div2 {background: green;position: relative; }
#div3 {background: orange;position: relative;} <div id="div1">
<div id="div2">
<div id="div3"></div>
</div>
</div> <script>
window.onload = function() {
var oDiv3 = document.getElementById('div3');
alert( oDiv3.offsetTop );
}
</script>
div3有定位父级则显示为到div2(父级)的距离
offsetTop
火狐,谷歌,360,opera:40 
ie7-11:40
ie7:如果自己没有定位,那么offsetTop是到body的距离 80 如果自己有定位,那么就是到定位父级的距离
offsetLeft
火狐,谷歌,360,opera:50 
ie7-11:50
ie7:如果自己没有定位,那么offsetTop是到body的距离 100 如果自己有定位,那么就是到定位父级的距离
 
 

.offsetLeft,.offsetTop的更多相关文章

  1. js的offsetWidth,offsetHeight,offsetLeft,offsetTop

    js的offsetWidth,offsetHeight,offsetLeft,offsetTop

  2. offsetLeft, offsetTop以及postion().left , postion().top有神马区别

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 1.offsetParent,offsetLeft,offsetTop

    offsetParent <!doctype html> <html> <head> <meta charset="utf-8"> ...

  4. offsetWidth, offsetHeight, offsetLeft, offsetTop,clientWidth, clientHeight,clientX,pageX,screenX

    offsetWidth: 元素在水平方向上占用的空间大小.包括元素的宽度,内边距,(可见的)垂直滚动条的宽度,左右边框的宽度. offsetHeight:元素在垂直方向上占用的空间大小,包括元素的高度 ...

  5. js中的offsetParent,offsetLeft,offsetTop及jquery的offset(),position()比较

    1.offsetParent 元素的offsetParent并不是元素的父元素,判断元素的offsetParent要根据以下情况: 1)当DOM结构层次中的元素均没有进行css定位(设置positio ...

  6. JavaScript--clientX,clientY、pageX,pageY、offsetLeft,offsetTop/offsetWidth,offsetHeight、scrollLeft,scrollTop/scrollWidth,scrollHeight、clientHeight,clientWidth区别

    /*在事件的内部console.dir(event)*/ /** * 事件对象event * clientX/clientY 获取鼠标基于浏览器窗口(可视区域的坐标位置)全兼容 * * pageX/p ...

  7. js中offsetLeft,offsetTop,offsetParent计算边距方法

    封装一个函数获得任一元素在页面的位置 var GetPosition= function (obj) { var left = 0; var top = 0; while(obj.offsetPare ...

  8. 一文看懂js中元素偏移量(offsetLeft,offsetTop,offsetWidth,offsetHeight)

    偏移量(offset dimension) 偏移量:包括元素在屏幕上占用的所有可见空间,元素的可见大小有其高度,宽度决定,包括所有内边距,滚动条和边框大小(注意,不包括外边距). 以下4个属性可以获取 ...

  9. JS获取元素的宽高以及offsetTop,offsetLeft等的属性值

    基本介绍 $(obj).width()与$(obj).height() $(obj).width()与$(obj).height() :jquery方式获取元素的宽高,不包括滚动条与工具条 $(obj ...

随机推荐

  1. How to use Ajax on Visualforce page on Salesforce platform

    Just use Ajax pattern to call object data from server on visualforce page. Following is the Asynchro ...

  2. ios 时间和毫秒数转换

    01-时间和毫秒数的相互转换 //获取毫秒数的时间戳 long inter = [[NSDate date] timeIntervalSince1970]*1000; NSLog(@"%ld ...

  3. LoadRunner参数化之数据生成方式

    一般需要使用多条数据来完成实际事务的时候,需要参数化.而使用参数化可以方便实现很多实际事务,记得在哪里看到过,参数化是比C函数更高级的函数. 参数化的方法 先来个最常见的LR示例的登录脚本: Acti ...

  4. 关于C/C++中数组元素的初始化

      1.一维数组初始化 对于一维数组,其初始化有一个错误的观点是:一直以为 int a[256]={0};是把a的所有元素初始化为0,int a[256]={1};是把a所有的元素初始化为1. 数组可 ...

  5. PHP入门 - - 05-->编写HTML页面的常用标签

    一.文字版面的编辑 1.格式标签 格式标签用于定义网页中文本的布局.缩进.位置.换行.列表等          <br>           换行          <p>   ...

  6. Android Studio导出Jar包并混淆

    在Android Studio中,自带反编译查看class文件,如果没有混淆的话,class文件跟java文件基本没有区别了,为了保护,还是混淆的好. 网上看了不少资料,都是直接下载proguard额 ...

  7. C#与mysql做ASP.NET网页数据库查询速度测试

    两种方法是:1,使用mysql数据库的存储过程:2,C#编码,做网页后台与mysql数据库连接,前台测试显示测试过结果下面我将分别讲解两种方法的具体实现. 1,使用mysql数据库的存储过程插入万条大 ...

  8. wpf,记录一下颜色设置的2中方法,,,

    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color ...

  9. three.js 场景入门

    <!DOCTYPE html> <html> <head> <title>Example 01.02 - First Scene</title&g ...

  10. WPF中ComboBox用法

    The ComboBox control is in many ways like the ListBox control, but takes up a lot less space, becaus ...