Skip to content

Instantly share code, notes, and snippets.

@kamichimo
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamichimo/84cf89433fae9cb18be2 to your computer and use it in GitHub Desktop.
Save kamichimo/84cf89433fae9cb18be2 to your computer and use it in GitHub Desktop.
ページ内スクロールにスムースなアニメーションをつける
jQuery(function($){
// #で始まるアンカーをクリックした場合に処理
$('.sm-scroll').click(function() {
// スクロールの速度
var speed = 400; // ミリ秒
// アンカーの値取得
var href= jQuery(this).attr("href");
// 移動先を取得
var target = jQuery(href == "#" || href == "" ? 'html' : href);
// 移動先を数値で取得
var position = target.offset().top;
// スムーススクロール
$('body,html').animate({scrollTop:position}, speed, 'swing');
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment