Last active
August 29, 2015 14:20
-
-
Save ocmca/e32f061167652e39409d to your computer and use it in GitHub Desktop.
Function takes in an element to find the top of it's position, also the speed (in milliseconds) at which the scroll should occur. Defaults to the top of the document at a "slow" tempo.
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
var scrollToTop = function(el, speed) { | |
/** | |
* Function takes in the element to scroll to, as well as | |
* the speed in which the document should scroll animate to the top. | |
* | |
* Default is window top, and slow (respectively). Time (in milliseconds is allowed) | |
*/ | |
"use strict"; | |
var position; | |
if(el === undefined){ | |
position = 0; | |
} else { | |
position = $(el).offset().top; | |
} | |
if(speed === undefined) speed = "slow" | |
$("html, body").animate({ scrollTop: position }, speed); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment