开发者

question about jquery scrolltop

I scroll down a page using jQuery. For example, With the code below, the page scroll down to a div id "bottom" by clicking a link. It works fine, but the url in the address bar remains same. I want that when I click the link, it scroll down as it does, but also add # (or whatever is the url of the link below) in the address bar of the browser. For example, the url of page is example.com/test.php, it should become something like example.com/test.php# Is it possible to do so? Thanks.

<a href="#" class="scrollToBottom">Scroll to bottom</a>

jQuery:

$(document).ready(function(){
        $('a.scrollToBottom').click(function(){
            $('html, body').animate({ scrollTop: $('#bottom').offset().top }, 'slow');
              开发者_开发百科  return false;       
        });
    })


You have to remove the return false line.

 $(document).ready(function(){
        $('a.scrollToBottom').click(function(){
            $('html, body').animate({ scrollTop: $('#bottom').offset().top }, 'slow');
        });
    })


Remove return false from your code it will work as you want.

    $(document).ready(function(){
        $('a.scrollToBottom').click(function(){
            $('html, body').animate({ scrollTop: $('#bottom').offset().top }, 'slow');
        });
    })
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜