console
var SCROLL_EVENT_KEY = 'scroll-bounced';
var BOUNCING_DISTANCE = 5;
var DATA_KEY = 'scroll.bounce';
$.event.special[SCROLL_EVENT_KEY] = {
bindType: 'scroll',
handle(event){
if ($(this).data(DATA_KEY) == undefined){
$(this).data(DATA_KEY, 0) ;
}
var offset = Math.abs(window.pageYOffset - $(this).data(DATA_KEY));
var scrolling = offset < 5
if (scrolling){
return
}
console.log(offset)
$(this).data(DATA_KEY, window.pageYOffset);
event.handleObj.handler.apply(this, arguments);
}
}
$(window).on(SCROLL_EVENT_KEY,function(){
const maxScroll = document.body.scrollHeight - window.innerHeight;
const percentage = window.pageYOffset / maxScroll * 100 + '%';
$('.scroll-bar-fixed-top').css('width', percentage);
})
<div class="scroll-bar-fixed-top"></div>
<div class="inner"></div>
.scroll-bar-fixed-top{
position: fixed;
top: 0;
height: 4px;
width: 0;
background: orange;
}
.inner{
height: 200vh;
}