Created
October 19, 2015 13:45
-
-
Save maru0014/57c1b431c6ced28c645e to your computer and use it in GitHub Desktop.
コピペでOK スムーズスクロール
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本体の読み込み --> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<!-- #リンクのスムーズスクロール --> | |
<script> | |
$(function(){ | |
// #で始まるリンクをクリックしたら実行されます | |
$('a[href^=#]').click(function() { | |
// スクロールの速度 | |
var speed = 400; // ミリ秒で記述 | |
var href= $(this).attr("href"); | |
var target = $(href == "#" || href == "" ? 'html' : href); | |
var position = target.offset().top; | |
$('body,html').animate({scrollTop:position}, speed, 'swing'); | |
return false; | |
}); | |
}); | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment