getBoundingClientRect()

getBoundingClientRect()

    这个方法返回一个矩形对象,包含四个属性:left、top、right和bottom。分别表示元素各边与页面上边和左边的距离。

    var box=document.getElementById('box');         // 获取元素

    alert(box.getBoundingClientRect().top);         // 元素上边距离页面上边的距离

posted @ 2016-03-29 09:34  找寻code屠龙之术  阅读(139)  评论(0编辑  收藏  举报