Last active
June 14, 2019 09:45
-
-
Save k-ish/7ec0b0574c4a532fdf7d814b0234b267 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
<div id="pagetop"><a href="#">ページの先頭へ</a></div> |
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
#pagetop { | |
display: none; | |
position: fixed; | |
bottom: 15px; | |
right: 10px; | |
z-index: 10000; | |
} |
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
// ページトップボタンを表示 | |
var topBtn = $('#pagetop'); | |
topBtn.hide(); | |
$(window).scroll(function () { | |
if ($(this).scrollTop() > 300) { | |
topBtn.fadeIn(); | |
} else { | |
topBtn.fadeOut(); | |
} | |
}); | |
topBtn.click(function () { | |
$('body,html').animate({ | |
scrollTop: 0 | |
}, 500); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment