Skip to content

Instantly share code, notes, and snippets.

@YasuakiHirano
Created July 11, 2016 07:42
Show Gist options
  • Save YasuakiHirano/fdcf9abcbdaf732a9f183ad854293eb5 to your computer and use it in GitHub Desktop.
Save YasuakiHirano/fdcf9abcbdaf732a9f183ad854293eb5 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<title></title>
<style>
#page-top {
position: fixed;
bottom: 20px;
right: 20px;
font-size: 77%;
}
#page-top a {
background: blue;
color: #fff;
padding: 10px 0;
width: 150px;
text-align: center;
display: block;
border-radius: 5px;
opacity:0.7;
text-decoration:none;
}
#page-top a:hover {
text-decoration: none;
background: #999;
}
#wrap{
min-height:1500px;
}
</style>
<script>
$(function() {
var topBtn = $('#page-top');
topBtn.hide();
$(window).scroll(function () {
// スクロール量が100以上の場合
if ($(this).scrollTop() > 100) {
topBtn.fadeIn();
} else {
topBtn.fadeOut();
}
});
topBtn.click(function () {
$('body,html').animate({
scrollTop: 0
}, 500);
return false;
});
});
</script>
</head>
<body>
<div id="wrap">
<p id="page-top"><a href="#wrap">PAGE TOP</a></p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment