Skip to content

Instantly share code, notes, and snippets.

@ajsharma
Forked from anonymous/gist:4422788
Last active December 10, 2015 10:48
Show Gist options
  • Save ajsharma/4423126 to your computer and use it in GitHub Desktop.
Save ajsharma/4423126 to your computer and use it in GitHub Desktop.
/**
* Overrides default JQuery.scrollTop to account for top header nav
* @requires JQuery
* @see http://api.jquery.com/scrollTop/
* @see https://github.com/jquery/jquery/blob/master/src/offset.js for scrollTop declaration
**/
(function($) {
var topOffset = 120; // height to account for in scrolling
// maintain a reference to the existing function
var jqueryScrollTop = $.fn.scrollTop;
// Overwriting the jQuery extension point
$.fn.scrollTop = function() {
console.log(arguments);
if(arguments.length > 0 && $.isNumeric(arguments[0])) {
arguments[0] = Math.max(0, arguments[0] - topOffset);
}
console.log(arguments);
// original behavior - use function.apply to preserve context
return jqueryScrollTop.apply(this, arguments);
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment