Last active
April 5, 2016 06:51
-
-
Save nekoneko-wanwan/7ba6c286b4b3093041619b0764f3498c to your computer and use it in GitHub Desktop.
スムーズスクロールをvelocity.jsで実装する
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
/* スムーズスクロールのイベント設定 */ | |
var addSmoothScrollEvent = function() { | |
var clickEventHandler = function() { | |
var href = $(this).attr('href'); | |
// #headerが指定されていればトップと見なす | |
var target = (href === '#' + $header.attr('id')) ? 'html' : href; | |
$(target).velocity('scroll', {duration: 500, easing: 'ease-in'}); | |
return false; | |
}; | |
$('a[href^="#"]').on('click.smooth', clickEventHandler); | |
// 値が#のみもしくは、data-no-scroll="true"設定時はイベント解除 | |
$('a[href="#"]').off('click.smooth'); | |
$('a[data-no-scroll="true"]').off('click.smooth'); | |
}; | |
addSmoothScrollEvent(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aタグにdata-no-scroll="true"を付けるとイベントを発動させない