1,000円
TOP
パーツ設置費用
CSS
#toTop {
background-color: #666666;
border-radius: 5px;
box-sizing: border-box;
cursor: pointer;
opacity: 0;
position: fixed;
bottom: 20px;
right: 20px;
transition: ease .5s;
height: 60px;
width: 60px;
z-index: -10;
}
#toTop.active {
opacity: 1;
z-index: 10;
}
#toTop:hover {
background-color: #ccc;
}
#toTop img {
image-rendering: -webkit-optimize-contrast;
position: absolute;
left: 50%;
top: 15px;
transform: translateX(-50%);
width: 21px;
}
#toTop p {
color: #fff;
font-family: 'Montserrat', sans-serif;
font-size: 14px;
position: absolute;
left: 0;
top: 30px;
text-align: center;
width: 100%;
}
HTML
<div id="toTop"> <img src="/wp/wp-content/uploads/2021/03/icon-arrow-up-white.png"> <p>TOP</p> </div>
JavaScript
<script>
jQuery(document).ready(function($){ $(window).on("scroll", function() { if ($(this).scrollTop() > 200) { $("#toTop").addClass('active'); } else { $("#toTop").removeClass('active'); } }); $('#toTop').click(function () { $('body,html').animate({ scrollTop: 0 }, 400); return false; }); });
</script>