I have the following simple jQuery:
$('#features').hide();
$('#more').click(function(e)
{
e.preventDefault();
$('#more').hide();
$('#features').show();
});
This shows a DIV when a user clicks the more link and using the preventDefault method the #features
hash isn't added to the url. However I still want to scroll down to that DIV in the same way as when a hash is passed to the url just not show it in the address bar. How do I do this? Thanks
Note: I'm not looking for any fancy effects etc so don't want to use plugins like scrollTo etc
You'll need to use $(window).scrollTop()
:
$('#more').click(function (e) {
e.preventDefault();
$('#more').hide();
$('#features').show();
$(window).scrollTop($('#features').offset().top);
});
Just use scrollTop
$('html, body').scrollTop($("div#features").offset().top);
http://jsfiddle.net/niklasvh/4XEVc/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With