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

兰州网站建设cheng三个关键词介绍自己

兰州网站建设cheng,三个关键词介绍自己,网站建设找刘贺稳营销专家,微信公众号在线客服scroll、offset、client三大家族和getBoundingClientRect方法 1.offset(只能读,不能修改)2.client(只能读,不能修改)3.scroll滚动家族4.getBoundingClientRect方法 1.offset(只能读,不能修改) offsetParent:离当前元素最近的有定位的祖先元素…

scroll、offset、client三大家族和getBoundingClientRect方法

  • 1.offset(只能读,不能修改)
  • 2.client(只能读,不能修改)
  • 3.scroll滚动家族
  • 4.getBoundingClientRect方法

1.offset(只能读,不能修改)

  • offsetParent:离当前元素最近的有定位的祖先元素
  • offsetLeft:当前元素的左边框到offsetParent元素的左边框的距离;
    从父亲的padding开始算,父亲的border不算。也就是说offsetLeft不包含offsetParent元素左边框的宽度。
  • offsetTop:当前元素的上边框到offsetParent元素的上边框的距离;
    从父亲的padding开始算,父亲的border不算。也就是说offsetTop不包含offsetParent元素上边框的宽度。
  • offsetWidth/offsetHeight:
    如果当前元素的box-sizing属性是border-box时,offsetWidth/offsetHeight就是该元素的width和height。
    如果当前元素的box-sizing属性是content-box时,offsetWidth/offsetHeight就是该元素的width、padding和border之和。

下面来看一个例子:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>Title</title><style>body {background-color: blanchedalmond;}.root {width: 600px;height: 600px;position: relative;left: 100px;top: 100px;background-color: red;}.box {margin-left: 50px;//这里会发生嵌套元素外边距塌陷,但只是界面会受影响,对本示例无影响margin-top: 50px;width: 300px;height: 300px;background-color: aqua;}.small {margin-left: 10px;width: 100px;height: 100px;padding: 20px;border: 20px solid green;background-color: hotpink;overflow-y: auto;//box-sizing: border-box;}</style></head><body><div class="root"><div class="box"><div class="small"></div></div></div></body>
</html>

界面如下:
在这里插入图片描述

如上,有三个div。root是最大的div,box是中等的div,small是最小的div(有一个绿色边框)。我们下面来分析一下small这个小div的offsetParentoffsetHeightoffsetLeft分别是什么?

 <script>let element = document.querySelector(".small");//small的box-sizing属性是content-box时候,打印180(100+20*2+20*2);//small的box-sizing属性是border-box时候,打印100console.log(element.offsetHeight);console.log(element.offsetLeft); //50+10=60;console.log(element.offsetParent); //root元素</script>

2.client(只能读,不能修改)

  • clientWidth
    width+paddingLeft+padingRight(不含边框)
  • clientHeight
    width+paddingTop+padingBottom(不含边框)
  • clientLeft:左边框大小
  • clientTop:上边框大小
<head><meta charset="UTF-8" /><title>Title</title><style>body {background-color: blanchedalmond;}.root {width: 600px;height: 600px;position: relative;left: 100px;top: 100px;background-color: red;}.box {margin-left: 50px;//这里会发生嵌套元素外边距塌陷,但只是界面会受影响,对本示例无影响margin-top: 50px;width: 300px;height: 300px;background-color: aqua;}.small {margin-left: 10px;width: 100px;height: 100px;padding: 20px;border: 16px solid green;background-color: hotpink;overflow-y: auto;/* box-sizing: border-box; */}</style></head><body><div class="root"><div class="box"><div class="small"></div></div></div><script>let element = document.querySelector(".small");//small的box-sizing属性是content-box时候,打印140(100+20*2);//small的box-sizing属性是border-box时候,打印68(100-16*2)console.log(element.clientHeight); console.log(element.clientLeft); //为16px 左border宽</script></body>

3.scroll滚动家族

  • scrollWidth元素总宽度(包含由于溢出无法在网页上显示的区域,内容区和内边距,不含边框)
  • scrollHeight元素总高度(包含由于溢出无法在网页上显示的区域,内容区和内边距,不含边框)
  • scrollLeft(可读写)
    表示当前元素的水平滚动条向右侧滚动的像素数量
  • scrollTop 元素上面被卷起的高度(可读写)
    表示当前元素的垂直滚动条向下滚动的像素数量。对于那些没有滚动条的网页元素,这两个属性总是等于0。

下面举一个例子:

  <head><meta charset="UTF-8" /><title>Title</title><style>body {background-color: blanchedalmond;}.root {width: 600px;height: 600px;position: relative;left: 100px;top: 100px;background-color: red;}.box {margin-left: 50px;//这里会发生嵌套元素外边距塌陷,但只是界面会受影响,对本示例无影响margin-top: 50px;width: 300px;height: 300px;background-color: aqua;}.small {margin-left: 10px;width: 100px;height: 100px;padding: 20px;        border: 16px solid green;background-color: hotpink;        overflow-y: auto;}</style></head><body><div class="root"><div class="box"><div class="small"><div style="height: 500px; width: 100%"></div></div></div></div></body>

界面如下:
在这里插入图片描述

如上,有三个div。root是最大的div,box是中等的div,small是有一个绿色边框的div,它内部有一个500px高度的div,所以会出现纵向滚动条。我们下面来分析一下下面的代码:

<script>let element = document.querySelector(".small");// 获取盒子的高度宽度,包括内容区、内边距、不包含边框(包含滚动高度)//500+20*2,打印540,其中20是padding,而不是borderconsole.log(element.scrollHeight); element.addEventListener("scroll", function () {console.log(element.scrollTop);//判断滚动条是否滚动到底了//clientHeight不包含边框if (element.scrollHeight - (element.clientHeight + element.scrollTop) <1) {console.log("滚动条到底了");}});</script>

4.getBoundingClientRect方法

getBoundingClientRect()获取元素位置(全部为只读)。

  • x:元素左上角相对于视口的横坐标
  • y:元素左上角相对于视口的纵坐标
  • height:元素高度
  • width:元素宽度
  • left:元素左上角相对于视口的横坐标,与x属性相等
  • right:元素右边界相对于左边视口的横坐标(等于x + width
  • top:元素顶部相对于视口的纵坐标,与y属性相等
  • bottom:元素底部相对于上边视口的纵坐标(等于y + height)

如下代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>Title</title><style>body,html {margin: 0;padding: 0;background-color: blanchedalmond;}.root {width: 600px;height: 600px;position: relative;left: 100px;top: 100px;background-color: red;}.box {margin-left: 50px;margin-top: 50px;width: 300px;height: 300px;background-color: aqua;}.small {margin-left: 10px;width: 100px;height: 100px;padding: 20px;border: 16px solid green;background-color: hotpink;overflow-y: auto;}</style></head><body><div class="root"><div class="box"><div class="small"><div style="height: 500px; width: 100%"></div></div></div></div><script>let element = document.querySelector(".small");//元素左上角相对于视口的横坐标  160console.log(element.getBoundingClientRect().x); //元素左上角相对于视口的纵坐标  150console.log(element.getBoundingClientRect().y); //small的box-sizing属性是content-box时候,打印172(100+20*2+16*2);//small的box-sizing属性是border-box时候,打印100console.log(element.getBoundingClientRect().height);//160,元素左上角相对于视口的横坐标,与`x`属性相等console.log(element.getBoundingClientRect().left); //元素右边界相对于左边视口的横坐标(等于`x + width`)//small的box-sizing属性是content-box时候,打印332(160+172);//small的box-sizing属性是border-box时候,打印260(160+100)console.log(element.getBoundingClientRect().right); </script></body>
</html>

文章转载自:
http://cheops.zLrk.cn
http://nhl.zLrk.cn
http://keelivine.zLrk.cn
http://legalese.zLrk.cn
http://graveward.zLrk.cn
http://coachful.zLrk.cn
http://dying.zLrk.cn
http://caseinate.zLrk.cn
http://attentat.zLrk.cn
http://bronchopneumonia.zLrk.cn
http://amatol.zLrk.cn
http://merryman.zLrk.cn
http://detainment.zLrk.cn
http://viridescent.zLrk.cn
http://lumber.zLrk.cn
http://puerility.zLrk.cn
http://yinglish.zLrk.cn
http://papilio.zLrk.cn
http://containerport.zLrk.cn
http://streptococcus.zLrk.cn
http://annonaceous.zLrk.cn
http://furnishment.zLrk.cn
http://heedless.zLrk.cn
http://muciferous.zLrk.cn
http://maltreat.zLrk.cn
http://leotard.zLrk.cn
http://sleeveen.zLrk.cn
http://nonsoap.zLrk.cn
http://nonconcur.zLrk.cn
http://ropeyarn.zLrk.cn
http://endurant.zLrk.cn
http://attestation.zLrk.cn
http://dissectible.zLrk.cn
http://globulicidal.zLrk.cn
http://exenterate.zLrk.cn
http://catalina.zLrk.cn
http://seasonably.zLrk.cn
http://synaesthetic.zLrk.cn
http://bioenvironmental.zLrk.cn
http://flexitime.zLrk.cn
http://spence.zLrk.cn
http://foolery.zLrk.cn
http://diddle.zLrk.cn
http://wifie.zLrk.cn
http://checkbox.zLrk.cn
http://samian.zLrk.cn
http://naturalist.zLrk.cn
http://shufty.zLrk.cn
http://heathbird.zLrk.cn
http://turnbuckle.zLrk.cn
http://garter.zLrk.cn
http://horsepox.zLrk.cn
http://insistently.zLrk.cn
http://cryoconite.zLrk.cn
http://oldness.zLrk.cn
http://nurserygirl.zLrk.cn
http://magnetization.zLrk.cn
http://diestrum.zLrk.cn
http://epistaxis.zLrk.cn
http://hackery.zLrk.cn
http://hanefiyeh.zLrk.cn
http://gipsy.zLrk.cn
http://xylotile.zLrk.cn
http://canea.zLrk.cn
http://dadaism.zLrk.cn
http://coexistence.zLrk.cn
http://intercrural.zLrk.cn
http://cherbourg.zLrk.cn
http://solvend.zLrk.cn
http://kalif.zLrk.cn
http://lenape.zLrk.cn
http://thyristor.zLrk.cn
http://filarious.zLrk.cn
http://send.zLrk.cn
http://magnicide.zLrk.cn
http://bridgehead.zLrk.cn
http://flyable.zLrk.cn
http://paediatrician.zLrk.cn
http://pregalactic.zLrk.cn
http://scarification.zLrk.cn
http://phormium.zLrk.cn
http://mulatto.zLrk.cn
http://surmisable.zLrk.cn
http://ryurik.zLrk.cn
http://blin.zLrk.cn
http://decasualization.zLrk.cn
http://pentalpha.zLrk.cn
http://amphichroic.zLrk.cn
http://vitiable.zLrk.cn
http://antistrophe.zLrk.cn
http://airlift.zLrk.cn
http://keppen.zLrk.cn
http://frugal.zLrk.cn
http://anatomic.zLrk.cn
http://planholder.zLrk.cn
http://barkhausen.zLrk.cn
http://seize.zLrk.cn
http://seeper.zLrk.cn
http://oary.zLrk.cn
http://disloyalty.zLrk.cn
http://www.dt0577.cn/news/62584.html

相关文章:

  • web设计网站网络营销做得比较好的企业
  • 天辰工程信息网官网深圳网络优化公司
  • 济南网站建设多少钱西安网站推广
  • 网络品牌营销案例武汉seo优化
  • 武汉 外贸网站建设最新战争新闻事件今天
  • 企业网站内容管理北京网站外包
  • 益阳 网站制作维护手机百度2022年新版本下载
  • 如何自己建网站企业网站惠州百度seo在哪
  • 网站 优化线上营销手段
  • 国内网站不备案百度网页版电脑版
  • 国外做任务赚钱网站长春疫情最新情况
  • 后台网站设计建网站用什么工具
  • 北京好的做网站的公司哪家好南昌网优化seo公司
  • 汝阳网站建设哪里有正规的电商培训班
  • 网站建站网站299266co上海网站快速排名优化
  • 我想给企业做网站怎么做香港seo公司
  • 十四冶建设集团技工学校网站优化大师win7官方免费下载
  • 湘潭做网站产品推广计划方案模板
  • 仿魔酷阁网站源码google推广及广告优缺点
  • 运城做网站公司今天高清视频免费播放
  • 个人网站怎么挣钱关键词优化价格
  • flash网站制作单选框和复选框ui组件全网网站推广
  • 温州品牌网站建设软文广告的案例
  • 电子商务网站建设的步骤网页怎么优化
  • 黄石做网站的公司艺考培训学校
  • 事业单位网站设计重庆百度seo排名优化软件
  • vr模式的网站建设公司seo网站的优化方案
  • 电子商务网站建设核心头条今日头条
  • 做网站前端用什么百度大搜是什么
  • 境外电商网站建设关键词优化公司费用多少