parentNode    直接父级//和offsetParent不同

inner2.parentNode
<!DOCTYPE html>
<html id="html">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#inner2{
position: absolute;
}
#wrap{
position: relative;
}
</style>
</head>
<body id="body">
<div id="wrap">wrap
<div id="inner1">inner1
<div id="inner2">inner2</div>
</div>
</div>
</body>
<script type="text/javascript">
//hmtl css js
window.onload=function(){
//parentNode 直接父级
var inner2 = document.querySelector("#inner2");
console.log(inner2.parentNode.id);
} </script>
</html>

offsetParent

a.有点类型于css中包含块(css中的概念)的概念
b.offsetLeft 和 offsetTop都是参照于offsetParent的内边距边界
c.规则(html和body之间的margin被清除)

本身定位为fiexd,不管你父级有没有定位

存在兼容性问题
火狐的offsetParent --> body


非火狐offsetParent --> null

<!DOCTYPE html>
<html id="html">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#wrap{position: absolute;}
#inner1{position: fixed;}
#inner2{position: relative;}
#inner3{position: fixed;} </style>
</head>
<body id="body">
<div id="wrap">wrap
<div id="inner1">inner1
<div id="inner2">inner2
<div id="inner3"></div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
/*
ev||event
鼠标滚轮
事件绑定
offsetParent
1.父级是否有定位(4种)
2.本身是否有定位(4种)
3.浏览器不一样(5大pc浏览器+老祖宗(ie 6 7 8)) 4*4*8 = 128 本身定位为fixed
==> offsetParent:null(不是火狐)
==> offsetParent:body(火狐) 本身定位不为fixed
父级没有定位
==> offsetParent:body
父级有定位
==> offsetParent:定位父级
*/ window.onload=function(){
console.log(inner3.offsetParent)
}
</script>
</html>

测试代码

非fixed
父级没有定位
offsetParent --> body
父级有定位
offsetParent --> 定位父级

fixed 不管你有没有定位都根据body

    <meta charset="UTF-8">
<title></title>
<style type="text/css">
#wrap{position: absolute;}
#inner1{position: fixed;}
#inner2{position: relative;}
#inner3{position: fixed;} </style>
</head>
<body id="body">
<div id="wrap">wrap
<div id="inner1">inner1
<div id="inner2">inner2
<div id="inner3"></div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
/*
ev||event
鼠标滚轮
事件绑定
offsetParent
1.父级是否有定位(4种)
2.本身是否有定位(4种)
3.浏览器不一样(5大pc浏览器+老祖宗(ie 6 7 8)) 4*4*8 = 128 本身定位为fixed
==> offsetParent:null(不是火狐)
==> offsetParent:body(火狐) 本身定位不为fixed
父级没有定位
==> offsetParent:body
父级有定位
==> offsetParent:定位父级
*/ window.onload=function(){
console.log(inner3.offsetParent)
}
</script>
</html>
<!DOCTYPE html>
<html id="html">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css"> html,body{
height: %;
overflow: hidden;
} #wrap{position: absolute;background: pink;left: 100px;top: 50px;}
#inner1{position: fixed;background: deeppink;left: 50px;top: 150px;}
#inner2{position: relative;background: hotpink;left: 80px;top: 70px;}
#inner3{position: fixed;background: yellow;left: 60px;top: 30px;}
div{
width: 200px;
height: 200px;
padding: 50px;
border: 10px solid;
}
</style>
</head>
<body id="body">
<div id="wrap">wrap
<div id="inner1">inner1
<div id="inner2">inner2
<div id="inner3">inner3</div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
/*
*
ev||event
鼠标滚轮
事件绑定
offsetParent
1.父级是否有定位(4种)
2.本身是否有定位(4种)
3.浏览器不一样(5大pc浏览器+老祖宗(ie 6 7 8)) 4*4*8 = 128 本身定位为fixed
==> offsetParent:null(不是火狐)
offsetTop和offsetLeft也是参照于body的
==> offsetParent:body(火狐) 本身定位不为fixed
父级没有定位
==> offsetParent:body
父级有定位
==> offsetParent:定位父级
*/ window.onload=function(){
console.log(inner3.offsetTop,inner3.offsetLeft)
}
</script>
</html>

Dom关于位置和尺寸的api的更多相关文章

  1. 获取DOM元素位置和尺寸大小

    JavaScript获取DOM元素位置和尺寸大小 在一些复杂的页面中经常会用JavaScript处理一些DOM元素的动态效果,这种时候我们经常会用到一些元素位置和尺寸的计算,浏览器兼容性问题也是不可忽 ...

  2. JavaScript获取DOM元素位置和尺寸大小

      在一些复杂的页面中经常会用JavaScript处理一些DOM元素的动态效果,这种时候我们经常会用到一些元素位置和尺寸的计算,浏览器兼容性问题也是不可忽略的一部分,要想写出预想效果的JavaScri ...

  3. JS中关于位置和尺寸的api

    HTMLElement.offsetParent 由于offsetTop 和 offsetLeft 都是相对于 offsetParent 内边距边界的,故offsetParent的意义十分重大.off ...

  4. DOM元素的位置、尺寸及更多的信息

    一.基本概念 document.documentElement是整个DOM树的根节点,对应的元素就是html.下面将其称作根元素或根节点. document.body,对应的元素是body 二.浏览器 ...

  5. Windows 系统上用 .NET/C# 查找所有窗口,并获得窗口的标题、位置、尺寸、最小化、可见性等各种状态

    原文:Windows 系统上用 .NET/C# 查找所有窗口,并获得窗口的标题.位置.尺寸.最小化.可见性等各种状态 在 Windows 应用开发中,如果需要操作其他的窗口,那么可以使用 EnumWi ...

  6. IOS中调整UI控件位置和尺寸

    1.frame(修改位置和尺寸):以父控件左上角为坐标原点,在其父控件中的位置和尺寸. //frame属性中的坐标点不能直接修改 CGRect tempFrame = self.v.frame; // ...

  7. jQuery 学习笔记(4)(文本值相关方法、操控CSS方法、位置和尺寸方法)

    1.文本值相关方法 .html() == .innerHTML $("div").html("<span> ...</span>") / ...

  8. jacascript DOM节点——节点获取与选择器API

    前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! DOM 操作必须等待 HTML 加载完毕之后,才可以获取节点:有两种方法: 把 script 标签放到代码 ...

  9. 根据经纬度获取位置描述:百度API与高德API的区别

    百度API 使用百度坐标 1.访问方式一 http://api.map.baidu.com/geocoder/v2/?location=35.063592,118.38513&output=j ...

随机推荐

  1. 1-vim-简介

    vi(visual interface)是Linux最经典的文本编辑器 vi的核心设计思想-让程序员的手指始终保持在键盘的核心区域,就能完成所有的编辑操作. vi的特点 没有图形界面 只能编辑文本内容 ...

  2. Avito Cool Challenge 2018 C - Colorful Bricks

    题目大意: 1*n的格子 可以用m种颜色涂色 已知从第2开始到第n个格子 有k个格子与其左边的格子颜色不同 求涂色的方案数 相当于把n个格子分成k+1份 可以递推出分成k+1份的不同的方案数(其实递推 ...

  3. ubuntu14.04标题栏显示上下网速

    首先当然是用 wget 下载 indicator-sysmonitor,终端执行命令: wget -c https://launchpad.net/indicator-sysmonitor/trunk ...

  4. 构建单页Web应用——简单概述

    一.开发框架 ExtJS可以称为第一代单页应用框架的典型,它封装了各种UI组件,用户主要使用JavaScript来完成整个前端部分,甚至包括布局.随着功能逐渐增加,ExtJS的体积也逐渐增大,即使用于 ...

  5. kindEditor富文本编辑器的工具栏设置

    如何配置kindeditor的工具栏 kindeditor编辑器的工具栏主要是指编辑器输入框上方的那些可以操作的菜单,默认情况下编辑器是给予了所有的工具栏.针对不同的用户,不同的项目,不同的环境,可能 ...

  6. pandas读书笔记、重新索引

      重新索引   pandas对象的一个重要方法是 reindex ,其作用是创建一个适应新索引的新对象. #reindex函数的参数 reindex(index,method,fill_value, ...

  7. Linux下Qt调用共享库文件.so

    修改已有的pro文件,添加如下几句: INCLUDEPATH += /home/ubuntu/camera/camera/LIBS += -L/home/ubuntu/camera/camera -l ...

  8. Boost.Interprocess

    https://github.com/svebert/InterprocessMsg 好像消息队列

  9. 使用sqlyog工具同步两个相同结构的数据库之间的数据

    compare two database data 因为工作上遇到 同一个项目被部署到不同服务器上,原项目(后统称"源")在运行中,后部署的项目(后统称"目标" ...

  10. 用Cygwin实现在window环境下使用Linux命令-nohup 来后台运行程序

    1.安装Cygwin 下载 cygdrive-选择64或32位   http://www.cygwin.com/ 注:可以百度搜索安装步骤 2.配置它的环境变量 添加到path路径中 3.cmd  执 ...