JSFiddle - React, Tailwind, and code Playground
by NunoMira
HTML
<h1>Top of the page</h1>
<article style="height: 1000px">
<p style="margin-bottom: 600px">Scroll down the page…</p>
<p>Then click the box.</p>
<a href="#" class="scrollup">Scroll</a>
</article>
CSS
.scrollup
{
position: fixed;
bottom: 50px;
right: 50px;
display: none;
}
JavaScript
//ScrollUp
$(document).ready(function ()
{
$(window).scroll(function ()
{
if ($(this).scrollTop() > 100)
$('.scrollup').fadeIn();
else
$('.scrollup').fadeOut();
});
$('.scrollup').click(function ()
{
$("html, body").animate({
scrollTop: 0
}, 600);
return false;
});
});