Skip to content

Instantly share code, notes, and snippets.

@AdsonCicilioti
Last active December 28, 2015 17:42
Show Gist options
  • Save AdsonCicilioti/1adf4f50b688ce2b8b19 to your computer and use it in GitHub Desktop.
Save AdsonCicilioti/1adf4f50b688ce2b8b19 to your computer and use it in GitHub Desktop.
jQuery(document).ready(function($) {
////// ANCHOR SMOOTH
$('a[href^="#"]').click(function(e) {
e.preventDefault();
anchorScroll( $(this), $($(this).attr('href')), 800 );
});
function anchorScroll(this_obj, that_obj, base_speed) {
var this_offset = this_obj.offset();
var that_offset = that_obj.offset();
var offset_diff = Math.abs(that_offset.top - this_offset.top);
var speed = (offset_diff * base_speed) / 1000;
$('html,body').animate({
scrollTop: that_offset.top - 150 // Set a negative value to compensate for a fixed height of the top bar
}, speed);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment