Last active
January 2, 2016 15:08
-
-
Save elfcobe/8321013 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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
「カスタマイズ」→「記事」→「記事下」へ追加。
スマートフォン版にも表示するにチェックを入れると幸せになれる・・・かも