Skip to content

Instantly share code, notes, and snippets.

@nekoneko-wanwan
Last active April 5, 2016 06:51
Show Gist options
  • Save nekoneko-wanwan/7ba6c286b4b3093041619b0764f3498c to your computer and use it in GitHub Desktop.
Save nekoneko-wanwan/7ba6c286b4b3093041619b0764f3498c to your computer and use it in GitHub Desktop.
スムーズスクロールをvelocity.jsで実装する
/* スムーズスクロールのイベント設定 */
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();
@nekoneko-wanwan
Copy link
Author

aタグにdata-no-scroll="true"を付けるとイベントを発動させない

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment