JSFiddle - React, Tailwind, and code Playground

by zaza zviaduari

HTML

<div class="content">
<div class="TopButton">UP</div>
</div>

CSS

.content{
  height:1000px
}
.TopButton{
  position:fixed;
  display:none
}

JavaScript

jQuery(document).ready(function($){
    //Check to see if the window is top if not then display button
    $(window).scroll(function(){
        if ($(this).scrollTop() > 100) {
            $('.TopButton').fadeIn();
        } else {
            $('.TopButton').fadeOut();
        }
    });
    //Click event to scroll to top
    $('.TopButton').click(function(){
        $('html, body').animate({scrollTop : 0},360);
        return false;
    });
});