收集一些常用的代码
 

获取元素到浏览器顶部的距离

function findPos(id) {

    var node = document.getElementById(id); 

    var curtop = 0;

    var curtopscroll = 0;

    if (node.offsetParent) {

        do {

            curtop += node.offsetTop;

            curtopscroll += node.offsetParent ? node.offsetParent.scrollTop : 0;

        } while (node = node.offsetParent);

        alert(curtop - curtopscroll);

    }

}


2013-10-19 /
标签: javascript
 
评论
© 代码|Powered by LOFTER