js控制滚动条位置

通过window.scrollTo(x,y); 这个函数控制滚动条的位置

        function getTop(e){
        var offset=e.offsetTop;

        if(e.offsetParent!=null)
        offset+=getTop(e.offsetParent);

        return offset;
        }

这个方法可以获得元素在body中的绝对位置。

原文地址:https://www.cnblogs.com/rebelboy/p/2023667.html