Bootstrap 4 - Online Course (Complete Course)

0 of 42 lessons complete (0%)

Bootstrap and jQuery

Local Scroll with custom jQuery script

This is a preview lesson

Purchase this course, or sign in if you're already enrolled, to take this lesson.

A beautifully animated local scroll or anchor jump is typical for the modern web. In this video I show you how to develop a corresponding script based on jQuery.

Here you can find the complete code for the local scroll with jQuery. Don't forget to use the full jQuery version for the animation and not only the slim version.

$( document ).ready(function() {
    
    $('.local-scroll').on('click', function(e){
        e.preventDefault();

        var href = $(this).attr('href');

        var offsetTop = $( href ).offset().top;

        if( href == '#unser-program' ) {
            offsetTop = offsetTop - 150;
        }

        $('html, body').animate({
            scrollTop: offsetTop
        }, 'slow');
    });
});