导航

div 滚动定位代码

Posted on 2015-01-23 11:26  高山老王  阅读(185)  评论(0)    收藏  举报


        var thisheith;
        $(function () {
            var divid = '#14681-121320-197209';
            $(divid).find("a").addClass("c-red").addClass("b");
            $(divid).bind("click", function () {
                change(this);
            });
            $(divid).click();
            ScrollDiv();
        });
        function ScrollDiv() {
            var ex = document.getElementById("nav");
            ex.scrollTop = thisheith-200;
        }
        function change(elem) {
            thisheith= getTop(elem);
        }
        function getTop(e) {
            var offset = e.offsetTop;
            if (e.offsetParent != null) {
                offset += getTop(e.offsetParent);
            }
            return offset;

        }