Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add offset to jQuery ScrollTo

Right now I am using a ScrollTo plugin as demonstrated in this fiddle. If you press the back/next button it will scroll you to the next post. The problem is that I have a fixed navigation bar and it blocks the posts. I did some research, both here and on the plugin author's blog and I learnt that you have to add an "offset" option. So I turned this

if (scroll) { 
            $.scrollTo(scroll, {
                duration: 750
            });
        }

into

if (scroll) { 
            $.scrollTo(scroll, {
                offset: -50
                duration: 750
            });
        }

However this just breaks the plugin and it stops working comepletely. I tried some other options as suggested by related posts but none of the methods worked.

/Tony

like image 485
Ming Avatar asked Mar 23 '26 02:03

Ming


1 Answers

You need a comma between offset and duration

offset: -50,
duration: 750

I notice it works with 50, but with -50 you need to first scroll down a little. Needs a bit more work ;)

like image 157
Andy G Avatar answered Mar 25 '26 16:03

Andy G



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!