Last active
August 29, 2015 14:14
-
-
Save tanshio/b690a3eaf3a847a82066 to your computer and use it in GitHub Desktop.
moveLink
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
$.fn.extend | |
moveLink: (options) -> | |
# Default settings | |
if !$(this).length > 0 | |
return | |
settings = { | |
fixedNav:"" | |
} | |
arr = [] | |
$navHeight = 0 | |
# Merge default settings with options. | |
settings = $.extend settings, options | |
if settings.fixedNav | |
$navHeight=$(settings.fixedNav).height() | |
$(this).on('click.moveLink',(e)-> | |
e.preventDefault() | |
anchor = $(this).attr("href") | |
if anchor is "#top" | |
anchorPos = 0 | |
$("html").velocity("scroll",{duration: 1000,offset: anchorPos,easing: "ease-in-out"}) | |
else | |
anchorPos = $(anchor).offset().top-$navHeight | |
$("html").velocity("scroll",{duration: 1000,offset: anchorPos,easing: "ease-in-out"}) | |
# console.log arr | |
) | |
$('.js-moveLink').moveLink() |
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
$.fn.extend({ | |
moveLink: function(options){ | |
// # Default settings | |
if(!$(this).length > 0) return; | |
var settings = { | |
fixedNav:"" | |
}; | |
settings = $.extend(settings, options); | |
var arr = [], | |
$navheight=0; | |
if(settings.fixedNav){ | |
$navHeight=$(settings.fixedNav).height() | |
} | |
$(this).on('click.moveLink',function(e){ | |
e.preventDefault(); | |
// リサイズする事も加味して一応 | |
// $(".content-nav .is-active").removeClass("is-active") | |
var anchor = $(this).attr("href"); | |
var anchorPos; | |
if(anchor === "#top"){ | |
anchorPos = 0; | |
$("html").velocity("scroll",{duration: 1000,offset: anchorPos,easing: "ease-in-out"}); | |
}else { | |
anchorPos = $(anchor).offset().top-$navheight; | |
$("html").velocity("scroll",{duration: 1000,offset: anchorPos,easing: "ease-in-out"}); | |
} | |
}) | |
} | |
}) | |
$('.js-moveLink').moveLink(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment