Computer Magic Logo
Scroll to element

Friday, January 22, 2016

Published by Aristotelis Pitaridis

We have an element with id "GoToElement" which will start the scrolling. We also have an element with id "TargetElement" which defines the position that we want to scroll.

$("#GoToElement").click(function() {
    $('html, body').animate({
        scrollTop: $("#TargetElement").offset().top
    }, 2000);
    return false;
});