Last active
August 29, 2015 14:07
-
-
Save kamichimo/84cf89433fae9cb18be2 to your computer and use it in GitHub Desktop.
ページ内スクロールにスムースなアニメーションをつける
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
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