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');
});
})
精彩评论