JSFiddle - React, Tailwind, and code Playground
HTML
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="scrollup">Click to scroll up</div>
CSS
.scrollup
{
width: 110px;
height: 30px;
background: red;
color: white;
border-radius: 10px;
position: fixed;
display: none;
right: 20px;
top: 260px;
}
JavaScript
$(document).ready(function() {
$(window).scroll(function(){
if ($(window).scrollTop() > 300){
$(".scrollup").fadeIn();
} else {
$(".scrollup").fadeOut();
}
});
});
$(document).ready(function(){
$(".scrollup").click(function(){
$('html, body').animate({scrollTop: '0px'}, 300);
});
});