Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Smooth Scroll Offset

Tags:

jquery

I have the following jQuery code

$(document).ready(function(){
    $('a[href^="#"]').on('click',function (e) {
        e.preventDefault();

        var target = this.hash,
        $target = $(target);

        $('html, body').stop().animate({
            'scrollTop': $target.offset().top
        }, 900, 'swing', function () {
            window.location.hash = target;
        });
    });
});

This is a scrolling plugin which scrolls down smoothly to internal links in a page. I would like to offset the school by -140px so it does not scroll right to the DIV.

How can this be achieved?

like image 670
user2716389 Avatar asked Dec 12 '22 10:12

user2716389


1 Answers

Try...

$('html, body').stop().animate({
    'scrollTop': $target.offset().top-140
}, 900, 'swing', function () {
    window.location.hash = target;
});
like image 117
Kierchon Avatar answered Jan 07 '23 00:01

Kierchon