<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

<div class="base">
  我是撐高度用的DIV~我不重要 <br>
  請往下滑後點選"回到頂端"
</div>
<div class="goTop">
  回到頂端
</div>
.base { height:800px;}

.goTop { position:fixed; top:50%; right:0; width:70px; height:70px; text-align:center; color:#fff; line-height:70px; background:rgba(0,0,0,0.8); cursor: pointer; transition: .5s;}
.goTop:hover { background:rgba(0,0,0,0.5); }
$(".goTop").click(function(){
  $("html,body").scrollTop( 0 );  
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.