Created
March 31, 2015 14:35
-
-
Save AaronLayton/684e47c2ec0682c80952 to your computer and use it in GitHub Desktop.
ScrollToElementNew
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
function ScrollToElement(elmID, scrollOffset) { | |
if (!scrollOffset) scrollOffset = 0; | |
$('html,body').animate({ scrollTop: $(elmID).offset().top - scrollOffset }, 'slow'); | |
} | |
function ScrollToElementNew(options, callback) { | |
var defaults = { | |
speed: 400, | |
scrollOffset:0, | |
easing: null | |
}; | |
options = $.extend({}, defaults, options); | |
$(options.target).trigger("before.scrolltoelement", options); | |
$('html,body').animate({ | |
scrollTop: options.target.offset().top - options.scrollOffset | |
}, options.speed, options.easing, function(){ | |
if (typeof(callback) == "function"){ | |
callback(options); | |
} | |
$(options.target).trigger("after.scrolltoelement", options); | |
}); | |
} | |
ScrollToElementNew({ | |
target: $(".my-thing"), | |
scrollOffset: 10, | |
andrew: 123 | |
}, function(data){ | |
console.log(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment