自动滚动到锚点

时间:2015-04-21 12:03:07

标签: jquery scroll

我有这段代码:

<script type='text/javascript'>//<![CDATA[ 
    $(window).load(function() {
        $(".scroll").click(function(event) {
            event.preventDefault();
            //calculate destination place
            var dest = 0;
            if ($(this.hash).offset().top > $(document).height() - $(window).height()) {
                 dest = $(document).height() - $(window).height();
            } else {
                 dest = $(this.hash).offset().top;
            }
            //go to destination
            $('html,body').animate({ scrollTop: dest }, 1000, 'swing');
        });
    });//]]>
</script>

当我必须首先点击链接时,如何在页面加载时立即滚动到#destination而不是现在滚动?

0 个答案:

没有答案