弹来弹去跑马灯!

JS获取元素相对窗口的位置和大小

利用:getBoundingClientRect 获取元素相对窗口的位置和大小

function test(){
var box = document.getElementById("btn1");
var pos = box.getBoundingClientRect();
console.log("top:"+pos.top +
  "left:"+pos.left +
  "bottom:"+pos.bottom +
  "right:"+pos.right +
  "width:"+pos.width +
  "height:"+pos.height);	 
		 
 }
	   

  

posted @ 2025-04-02 21:57  wgscd  阅读(31)  评论(1)    收藏  举报