Last active
December 28, 2015 17:42
-
-
Save AdsonCicilioti/1adf4f50b688ce2b8b19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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