Skip to content

Instantly share code, notes, and snippets.

@k7y6t5
Last active August 29, 2015 14:01
Show Gist options
  • Save k7y6t5/ee2dd806bad8b948a909 to your computer and use it in GitHub Desktop.
Save k7y6t5/ee2dd806bad8b948a909 to your computer and use it in GitHub Desktop.
/*-----------------------
@SCROLLTO
required: http://demos.flesler.com/jquery/scrollTo/
optional: https://github.com/gdsmith/jquery.easing
------------------------*/
ww.scrollto = (function(){
var settings = {
$trigger: $(".btn--scroll"),
scroll_rate: 200,
$offset_el: $(".off-canvas"),
$navbar: $(".navbar"),
my_offset: 0,
};
return {
init: function() {
settings.$trigger.on("click", function(e){
e.preventDefault();
hash = $(this).attr("href").replace("#", "");
$scroll_target = $("[name='"+hash+"']");
if (settings.$offset_el.css("position") == "fixed") {
settings.my_offset = settings.$navbar.outerHeight();
} else {
settings.my_offset = 0;
}
$.scrollTo($scroll_target, settings.scroll_rate, {
offset: -settings.my_offset,
});
});
},
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment