JQuery show div and scroll to it without hashtag in url

I have the following simple jQuery:

$('#features').hide(); $('#more').click(function(e) { e.preventDefault(); $('#more').hide(); $('#features').show(); }); 

This shows the DIV when the user clicks the link more, and using the preventDefault method, the #features hash #features not added to the URL. However, I still want to scroll down to this DIV in the same way as when the hash is passed in the url, just don't show it in the address bar. How can I do it? Thanks

Note. I'm not looking for any fancy effects, etc., so I don't want to use plugins like scrollTo, etc.

+7
source share
2 answers

You will need to use $(window).scrollTop() :

 $('#more').click(function (e) { e.preventDefault(); $('#more').hide(); $('#features').show(); $(window).scrollTop($('#features').offset().top); }); 
+4
source

Just use scrollTop

 $('html, body').scrollTop($("div#features").offset().top); 

http://jsfiddle.net/niklasvh/4XEVc/

+1
source

All Articles