Scroll to anchor with jQuery

Today I needed to create link with anchor. When I pushed it, it opens new page and add class to div. The source code is:

var class= window.location.href.slice(window.location.href.indexOf('#') + 1).split('#');
if(class){
jQuery('.testimonial_cont').find('.'+class).show('slow');
jQuery('html,body').animate({scrollTop: jQuery('.testimonial_cont').find('.'+class).parent().offset().top},'slow');
}

Of course you can change slow to normal or fast or even a int in milliseconds.

I hope it will help for someone.

Leave a Reply

Your email address will not be published. Required fields are marked *