首页 > 其他 > 详细

6.2.25 BOM offset系列

时间:2018-07-22 10:22:29      阅读:142      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		
	</head>
	<body>
		<div style="position: relative;">
			
	
			<div id="box" style="width: 200px;height: 200px;border: 1px solid red; padding: 10px;margin: 10px;position: absolute;top: 20px;left: 30px;">
				
			</div>
		</div>
	</body>
	<script type="text/javascript">
		window.onload = function(){
			var box = document.getElementById(‘box‘)
			
			//占位宽 高 Top Left  
			
			/*
			 * offsetTop: 如果盒子没有设置定位 到浏览器的顶部的距离,如果盒子设置定位,那么是以父盒子为基准的top值
			 * offsetLeft: 如果盒子没有设置定位 到浏览器的左部的距离,如果盒子设置定位,那么是以父盒子为基准的left值
			 * offsetWidth 内容+padding+border
			 * */
			console.log(box.offsetTop)
			console.log(box.offsetLeft)
			console.log(box.offsetWidth)
			console.log(box.offsetHeight)
			
		}
		
	</script>
</html>

  

6.2.25 BOM offset系列

原文:https://www.cnblogs.com/beallaliu/p/9349092.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!