摘要:
下文讲述dom对象之offsetLeft属性值的功能简介说明,如下所示:
DOM之offsetLeft属性值说明
DOM之offsetLeft属性值功能说明:
offsetLeft属性值用于返回一个DOM元素相对于的”父级定位元素”的左边偏移量(左边的距离(像素))
DOM之offsetLeft属性值注意事项:
1.此属性是一个只读属性
2.当父级元素拥有定位属性时,此时返回最近的一个拥有定位属性的父级元素
3.当父级元素及最定级的父级元素都没有拥有定位属性时,此时返回最近的table td th 或body元素信息
4.此属性可应用于所有流行的浏览器
DOM之offsetLeft属性值语法:
DOM.offsetLeft
DOM之offsetLeft属性值举例说明
猫猫教程(www.maomao365.com)---offsetLeft属性值获取---左则偏移量
#one{width:180px;height:180px;position:absolute;top:30px;left:20px;background:red;}
#two{width:160px;height:120px;background:blue;}
#three{width:60px;height:80px;background:green;line-height:50px;
margin-left:30px;
color:white;font-weight:bold;}
window.οnlοad=function(){
let oMessage=document.getElementById("three");
oMessage.innerHTML=oMessage.offsetLeft+"像素";
}
maomao365.com
DOM对象之offsetLeft属性-左则偏移量举例说明