Created
January 27, 2013 07:49
-
-
Save artofhuman/4647271 to your computer and use it in GitHub Desktop.
Javascript: ScrollToElement
This file contains 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
/** | |
* Scrol to elem | |
* @param {String} selector [description] | |
* @param {Function} callback [description] | |
*/ | |
function scrollToElement(selector, callback){ | |
var animation = {scrollTop: $(selector).offset().top}; | |
console.log(selector); | |
$('html,body').animate(animation, 'slow', 'swing', function() { | |
if (typeof callback == 'function') { | |
callback(); | |
} | |
callback = null; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment