Skip to content

Instantly share code, notes, and snippets.

@cocuh
Last active December 19, 2015 10:19
Show Gist options
  • Save cocuh/5939964 to your computer and use it in GitHub Desktop.
Save cocuh/5939964 to your computer and use it in GitHub Desktop.
ページ内scrollをアニメーションにするテスト
$(function () {
function scrollTo(a) {
return function (e) {
var t={"top":0}[a]
if (typeof t=="undefined"){
t = $($(this).attr("href")).offset().top - document.getElementById('nav').clientHeight;
}
$('html, body').animate({scrollTop: t}, 500);
delete t;
e.preventDefault();
return false;
}
};
$('a[href^="#"]').click(scrollTo());
$('a[href=""]').click(scrollTo("top"));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment