JSFiddle - React, Tailwind, and code Playground
by irvandev
HTML
<div id='scroll'></div>
<h1>SILAHKAN SCROLL MOUSE ANDA
</h1>
<pre class="prettyprint">SILAHKAN SCROLL MOUSE ANDA</pre>
<h2>Get More Tutorials From <a href='http://irvandev.blogspot.com' rel='copyright'>Blog Irvan Dev</a>
</h2>
CSS
#scroll {
display:none;
position:fixed;
top:0;
right:15px;
z-index:500;
padding:3px 8px;
background-color:#000;
color:#fff;
border-radius:3px;
font-size:14px;
}
#scroll:after {
content: " ";
position: absolute;
top:50%;
right:-10px;
height:0;
width:0;
margin-top:-6px;
border:6px solid transparent;
border-left-color:#369fcf;
}
body{background:#dfedf1;
}
h1{text-align:center;margin:200px;color:black;
}
h2{text-align:center;margin:500px;color:red;
}
pre,code{background:#ffffff;color:#FF0000;margin:200px;font-family:"Courier New",Courier,Monospace;color:inherit;
}
pre{border:1px solid #181818;white-space:pre;word-wrap:normal;overflow:auto;
}
a {text-decoration:noe;}
JavaScript
var scrollTimer = null;
$(window).scroll(function() {
var viewportHeight = $(this).height(),
scrollbarHeight = viewportHeight / $(document).height() * viewportHeight,
progress = $(this).scrollTop() / ($(document).height() - viewportHeight),
distance = progress * (viewportHeight - scrollbarHeight) + scrollbarHeight / 2 - $('#scroll').height() / 2;
$('#scroll')
.css('top', distance)
.text(' (' + Math.round(progress * 100) + '%)')
.fadeIn(600);
if (scrollTimer !== null) {
clearTimeout(scrollTimer);
}
scrollTimer = setTimeout(function() {
$('#scroll').fadeOut(600);
}, 1000);
});