jQuery Scroll to with Pixel Adjustment

Can bet setup to occur automatically onload. If there is a large menu section that you’d like visitors to scroll past on subpages.

Original (sourced here):

$('html, body').stop().animate({

    'scrollTop': $target.offset().top + (-40)

}, 900, 'swing', function () {

    window.location.hash = target;

});

Adjusted for page specific loading:

jQuery(document).ready(function(){
	REL.init();
});

var REL = {};

REL.init = function() {

	if (jQuery('.page-child').length > 0) {

		REL.signpost_scroll();

	} else if (jQuery('.blog').length > 0 ) {

		REL.signpost_scroll();

	}
}

REL.signpost_scroll = function() {

	jQuery('html, body').stop().animate({

	    'scrollTop': jQuery('#target').offset().top + (-40)

	}, 900, 'swing', function () {

	    window.location.hash = jQuery('#target');

	});
}

 

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.