Rich - Pixel Vector
Rich - Pixel Vector

Reputation: 5

Jquery Scrolling

I have implemented the following code from this page: http://tympanus.net/codrops/2010/06/02/smooth-vertical-or-horizontal-page-scrolling-with-jquery/

 $(document).ready(function() {

            $('ul.navone li a, ul.navtwo li a,a.toplink, a.bodylink').bind('click',function(event){
                var $anchor = $(this);

                $('html, body, header').stop().animate({
                    scrollTop: $($anchor.attr('href')).offset().top
                }, 1500,'easeInOutExpo');

                event.preventDefault();
            });
        });

This all works correctly.

However, in my layout I have a fixed header div (i.e. it stays in place when the user scrolls). Therefore I need to set an offset for the scrolling script of 117 pixels.

How do I do this please?

Upvotes: 0

Views: 3372

Answers (1)

GregM
GregM

Reputation: 2654

Would be something like that :

$(document).ready(function() {

            $('ul.navone li a, ul.navtwo li a,a.toplink, a.bodylink').bind('click',function(event){
                var $anchor = $(this);

                $('html, body, header').stop().animate({
                    scrollTop: ($($anchor.attr('href')).offset().top + 117)
                }, 1500,'easeInOutExpo');

                event.preventDefault();
            });
        });

just add the +117 to the scrollTop position

Upvotes: 2

Related Questions