<p id="pageTop"><a href="#"><i class="fa fa-chevron-up"></i></a></p>
(footer手前に記述)
#pageTop {
position: fixed;
bottom: 2rem;
right: 2rem;
}
#pageTop a {
display: flex;
justify-content: center;
align-items: center;
z-index: 999;
border-radius: 3rem;
width: 3.5rem;
height: 3.5rem;
background-color: #00188b;
color: #fff;
font-weight: bold;
text-decoration: none;
text-align: center;
}
#pageTop a:hover {
text-decoration: none;
opacity: 0.7;
}//■page topへ戻るボタン
$(function () {
var topBtn = $("#pageTop");
topBtn.hide();
//◇ボタンの表示設定
$(window).scroll(function () {
if ($(this).scrollTop() > 80) {
//---- 画面を80pxスクロールしたら、ボタンを表示する
topBtn.fadeIn();
} else {
//---- 画面が80pxより上なら、ボタンを表示しない
topBtn.fadeOut();
}
});
// ◇ボタンをクリックしたら、スクロールして上に戻る
topBtn.click(function () {
$("body,html").animate(
{
scrollTop: 0,
},
500,
);
return false;
});
});