Skip to content

Instantly share code, notes, and snippets.

@Schniz
Last active December 11, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Schniz/4644718 to your computer and use it in GitHub Desktop.
Save Schniz/4644718 to your computer and use it in GitHub Desktop.
scrolls the browser to a place in the window. FUN FUN FUN.
/**
* Nicely scrolls the window to a certain place in a page
* @param whereTo jQuery|px to scroll to
* @param speed in ms. default - 700
* @param easing the easing. default - easeOutCirc
*/
scrollWindowTo = function(whereTo, speed, easing) {
if (!speed) speed = 700;
if (!easing) easing = jQuery.easing["easeOutCirc"] ? "easeOutCirc" : null;
if (whereTo instanceof jQuery) {
whereTo = whereTo.offset().top;
}
$('html,body').animate({scrollTop: whereTo}, speed, easing);
};
/**
* jQuery function
* @param speed in ms
* @param easing
*/
$.fn.scrollHere = function(speed, easing) {
scrollWindowTo($(this), speed, easing);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment