JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#" class="gototop">Top</a>
CSS
body {
margin:0;
min-height: 800px;
}
.gototop {
position: fixed;
bottom: 0;
right: 20px;
height: 60px;
background: yellow;
display: none;
color: black;
text-decoration: none;
}
JavaScript
var Blue = {
MIN_SCROLL_HEIGHT: 200,
button: null,
buttonVisibleFlag: null,
init: function () {
this.button = $(".gototop");
this.buttonVisibleFlag = false;
this.setWindowBindings();
},
setWindowBindings: function () {
$(window).scroll(function () {
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function () {
Blue.impress();
}, 150));
});
},
impress: function () {
if ($(window).scrollTop() > this.MIN_SCROLL_HEIGHT) {
this.button.slideDown();
} else if ($(window).scrollTop() <= this.MIN_SCROLL_HEIGHT) {
this.button.slideUp();
}
}
}
$(document).ready(function () {
Blue.init();
});