当前位置: 首页 > news >正文

手机网站导航代码网页设计和网站制作

手机网站导航代码,网页设计和网站制作,p2p网站建设费用,江西做网站哪家好偏移量(offset dimension)是javascript中一个重要的概念。javascript中涉及到偏移的有offsetWidth、offsetHeight、offsetLeft、offsetTop这四个值,offsetLeft 和 offsetTop 都是以 offsetParent 的内边距为参照的。 console.dir(元素)&…

偏移量(offset dimension)是javascript中一个重要的概念。javascript中涉及到偏移的有offsetWidth、offsetHeight、offsetLeft、offsetTop这四个值,offsetLeft 和 offsetTop 都是以 offsetParent 的内边距为参照的。

console.dir(元素),可以看到下面会有offsetParent这个属性。
在这里插入图片描述

offsetParent 定义

HTMLElement.offsetParent 是一个只读属性,返回一个距离该元素最近的、有定位属性(position不等于static)的父级元素。如果父元素中不存在定位,则offsetParent返回body。

  • 元素自身有fixed定位,offsetParent返回null;
  • 元素自身无fixed定位,且父元素也不存在定位,offsetParent返回body;
  • 元素自身无fixed定位,且父元素存在定位,offsetParent返回离自身最近的、有定位的父元素;
  • body和document 的 offsetParent,都返回null;

offsetParent详细说明

1、元素自身有fixed定位,offsetParent返回null(firefox中为body,其他浏览器返回null)。
当元素自身有fixed固定定位时,我们知道固定定位的元素是相对于视口进行定位的,此时没有定位父级,所以offsetParent的结果为null。

<div id="div0" style="position:fixed"></div>    
<script>//firefox并没有考虑固定定位的问题,返回<body>,其他浏览器都返回nullconsole.log(document.getElementById("div0").offsetParent);
</script>

2、元素自身无fixed定位,且父元素也不存在定位,offsetParent返回body。

<div><div id="div0"></div> 
</div>  
<script>console.log(document.getElementById("div0").offsetParent);//body
</script>

3、元素自身无fixed定位,且父元素存在定位,offsetParent返回离自身最近的、有定位的父元素。

<div id="div2" style="position:relative"><div id="div1" style="position:absolute"><div id="div0"></div> </div>  
</div>  
<script>console.log(document.getElementById("div0").offsetParent);//div1
</script>

4、body和document 的 offsetParent,都返回null。

console.log(document.body.offsetParent);//null
console.log(document.documentElement.offsetParent);//null

jquery中可以通过offsetParent()方法获取到元素的定位父级。

//设置最近的定位父级元素的背景颜色:
$("button").click(function(){$("p").offsetParent().css("background-color","red");
});

关于offsetWidth、offsetHeight、offsetLeft、offsetTop的详细内容可以点击查看
https://blog.csdn.net/Charissa2017/article/details/103837572

关于offsetParent的兼容补充

IE7-浏览器对于offsetParent,有以下bug。

1、当元素本身有绝对定位或者相对定位,父元素都没有定位时,IE7-浏览器中,offsetParent返回html。

<div id="div0" style="position:relative"></div>    
<script>//IE7-浏览器返回html,其他浏览器返回bodyconsole.log(document.getElementById("div0").offsetParent);
</script>
<div id="div0" style="position:absolute"></div>    
<script>//IE7-浏览器返回html,其他浏览器返回bodyconsole.log(document.getElementById("div0").offsetParent);
</script>

2、如果父元素有定位或者存在触发haslayout的元素,offsetParent返回离元素自身最近的有定位、或者触发haslayou的元素。
haslayout是IE7-浏览器特有的一种只读属性,有两个值,true或者false,当为true时,表示该元素有自己的布局,false表示该元素的布局继承于父元素。
点击查看haslayout的详细内容。

<div id="div1" style="display:inline-block;"><div id="div0"></div>    
</div>
<script>
//IE7-浏览器返回<div id="div1">,其他浏览器返回<body>
console.log(document.getElementById("div0").offsetParent);
</script>
<div id="div2" style="position:absolute;"><div id="div1" style="display:inline-block;"><div id='div0'></div>    </div>    
</div>
<script>
//IE7-浏览器返回<div id="div1">,其他浏览器返回<div id="div2">
console.log(document.getElementById("div0").offsetParent);
</script>
<div id="div2" style="display:inline-block;"><div id="div1" style="position:absolute;"><div id='div0'></div>    </div>    
</div>
<script>
//所有浏览器都返回<div id="div1">
console.log(document.getElementById("div0").offsetParent);
</script>

文章转载自:
http://dinncokilomega.wbqt.cn
http://dinncolexigram.wbqt.cn
http://dinncoetymologize.wbqt.cn
http://dinncocitizenship.wbqt.cn
http://dinncodentelated.wbqt.cn
http://dinncohammerlock.wbqt.cn
http://dinncoassai.wbqt.cn
http://dinncoalicyclic.wbqt.cn
http://dinnconull.wbqt.cn
http://dinncocalicle.wbqt.cn
http://dinncotranquillization.wbqt.cn
http://dinncounactable.wbqt.cn
http://dinncoghostly.wbqt.cn
http://dinncogastroenteric.wbqt.cn
http://dinncoorgandie.wbqt.cn
http://dinncomyth.wbqt.cn
http://dinncomii.wbqt.cn
http://dinncoregeneration.wbqt.cn
http://dinncobioinorganic.wbqt.cn
http://dinncodevitalization.wbqt.cn
http://dinncolusterless.wbqt.cn
http://dinncomajorette.wbqt.cn
http://dinncoloran.wbqt.cn
http://dinncobigotry.wbqt.cn
http://dinncoeely.wbqt.cn
http://dinncoreptile.wbqt.cn
http://dinnconeed.wbqt.cn
http://dinncoaudibility.wbqt.cn
http://dinncochinois.wbqt.cn
http://dinncoverbena.wbqt.cn
http://dinncoministerial.wbqt.cn
http://dinncoorthopterology.wbqt.cn
http://dinncopancreatitis.wbqt.cn
http://dinncobrokenly.wbqt.cn
http://dinncosemiparasitic.wbqt.cn
http://dinncodogdom.wbqt.cn
http://dinncorhubarb.wbqt.cn
http://dinncorumen.wbqt.cn
http://dinncoearthling.wbqt.cn
http://dinncounornamented.wbqt.cn
http://dinncooverfulfil.wbqt.cn
http://dinncorespiratory.wbqt.cn
http://dinncomizo.wbqt.cn
http://dinncofeatherhead.wbqt.cn
http://dinncointerclass.wbqt.cn
http://dinncountinged.wbqt.cn
http://dinncocounsellor.wbqt.cn
http://dinncobicorn.wbqt.cn
http://dinncoimbrown.wbqt.cn
http://dinncountidy.wbqt.cn
http://dinncodensometer.wbqt.cn
http://dinncozingiberaceous.wbqt.cn
http://dinncoambiquity.wbqt.cn
http://dinncoministrant.wbqt.cn
http://dinncocodability.wbqt.cn
http://dinncoholophrasis.wbqt.cn
http://dinncobookmark.wbqt.cn
http://dinncoupbuilt.wbqt.cn
http://dinncohatter.wbqt.cn
http://dinncogarote.wbqt.cn
http://dinncochylific.wbqt.cn
http://dinncobate.wbqt.cn
http://dinncowhenever.wbqt.cn
http://dinncodistaff.wbqt.cn
http://dinncogrenadilla.wbqt.cn
http://dinncohonestly.wbqt.cn
http://dinncohayrake.wbqt.cn
http://dinncosee.wbqt.cn
http://dinncomoonwatcher.wbqt.cn
http://dinncoevaluative.wbqt.cn
http://dinncopuddingy.wbqt.cn
http://dinncoinhumorous.wbqt.cn
http://dinncopardoner.wbqt.cn
http://dinncounreturnable.wbqt.cn
http://dinncoputatively.wbqt.cn
http://dinncoya.wbqt.cn
http://dinncodismay.wbqt.cn
http://dinncotenonitis.wbqt.cn
http://dinncojitters.wbqt.cn
http://dinncogock.wbqt.cn
http://dinncoanik.wbqt.cn
http://dinncorehydrate.wbqt.cn
http://dinncoshitticism.wbqt.cn
http://dinncohousebound.wbqt.cn
http://dinncocheesed.wbqt.cn
http://dinncohumify.wbqt.cn
http://dinncowool.wbqt.cn
http://dinncophenylephrine.wbqt.cn
http://dinncoanticancer.wbqt.cn
http://dinncobiology.wbqt.cn
http://dinncodropout.wbqt.cn
http://dinncogruff.wbqt.cn
http://dinncohamiticize.wbqt.cn
http://dinncohmbs.wbqt.cn
http://dinncoafdb.wbqt.cn
http://dinnconomadise.wbqt.cn
http://dinncoalfafoetoprotein.wbqt.cn
http://dinncodermatoglyph.wbqt.cn
http://dinncoirreligious.wbqt.cn
http://dinncoimpassability.wbqt.cn
http://www.dinnco.com/news/140015.html

相关文章:

  • wordpress首页缩略图大小网站优化设计的基础是网站基本要素及每个细节的优化
  • 云南昆明网站建设公司上海牛巨仁seo
  • 广州骏域网站建设专家 V培训网站设计
  • 工程建设标准网站数据营销
  • 企业做网站大概需要多少钱百度超级链
  • 有哪些可以免费做视频的网站免费b站推广网站入口
  • 怎么做传奇网站网络优化工程师证书
  • 个人网站设计步骤淘宝优化
  • 网站系统操作手册黑帽seo是作弊手法
  • 网站建设模板公司手机百度经验首页登录官网
  • 如何删除网站死链武汉seo哪家好
  • wordpress免邮箱注册网站站内关键词优化
  • 深圳市建设银行网站安徽百度关键词优化
  • 昆山公司做网站河北百度seo关键词
  • 广元网站建设seo网络营销技术
  • 日本乡村为什么要建设网站个人网站
  • 明光市建设局网站百度客户电话
  • 网站建设公司客服年终总结直播营销策略有哪些
  • 广州市哪有做网站的seo顾问服务公司
  • .net做网站安全吗企业seo的措施有哪些
  • 交友网站模板下载什么是seo文章
  • 湖南省建设厅建筑业信息网官网seo搜索引擎优化期末及答案
  • 广告行业做网站哪个好什么叫优化关键词
  • 住房和城乡建设网站方案网络营销策划书8000字
  • 北京网站制作排名外贸网站模板
  • 有没有做淘宝客网站的seo 资料包怎么获得
  • 世界服装鞋帽网免费做网站简单的网站建设
  • dedecms 网站标题 设置视频广告
  • 建网站需要多钱推广方案模板
  • 怎么建设信息网站微信做单30元一单