Skip to content

Instantly share code, notes, and snippets.

@elfcobe
Last active January 2, 2016 15:08
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 elfcobe/8321013 to your computer and use it in GitHub Desktop.
Save elfcobe/8321013 to your computer and use it in GitHub Desktop.
はてなブログでページトップへ移動ボタンを実装
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(function() {
var topBtn = $('#page-top');
topBtn.hide();
//スクロールが100に達したらボタン表示
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
topBtn.fadeIn();}
else { topBtn.fadeOut();
}
});
//スクロールしてトップ
topBtn.click(function () {
$('body,html').animate({
scrollTop: 0}, 500);
return false;
});
});
</script>
<style>
#page-top {
position: fixed;
bottom: 20px;
right: 20px;
font-size: 77%;
/*フォントのサイズ*/
}
#page-top a {
background: #666;
/*ボタンの背景色*/
text-decoration: none;
color: #fff;/*文字色*/
width: 100px;
/*ボタンの幅*/
padding: 30px 0;
/*文字周りのスペース*/
text-align: center;
/*文字位置*/
display: block;
border-radius: 5px;
/*ボタンの角丸加減*/
}
#page-top a:hover {
text-decoration: none;
background: #999;
/*ボタンに触れた時の背景色*/
}
</style>
<p id="page-top"><a href="#grobalheader-container">⇧ PAGE TOP</a></p>
@elfcobe
Copy link
Author

elfcobe commented Jan 8, 2014

「カスタマイズ」→「記事」→「記事下」へ追加。
スマートフォン版にも表示するにチェックを入れると幸せになれる・・・かも

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment