JSFiddle - React, Tailwind, and code Playground
HTML
<div class="container">
<div>
scroll me<br/>
scroll me<br/>
scroll me<br/>
scroll me<br/>
scroll me<br/>
scroll me<br/>
scroll me<br/>
scroll me<br/>
scroll me<br/>
scroll me<br/>
</div>
</div>
<br/>
<div class="first">Please scroll the box above</div>
<div class="delay"></div>
<br/>
<div class="scroll">scroll fired: 0 times</div>
<div class="mousewheel">mousewheel fired: 0 times</div>
CSS
.container {
height: 100px;
width: 100px;
background: #eee;
overflow: scroll;
}
JavaScript
var scroll = 0;
var mousewheel = 0;
var firstScroll, firstMousewheel;
$('.container').on('scroll', function() {
$('.scroll').html('scroll fired: ' + ++scroll + ' times');
if (scroll === 1) {
firstScroll = Date.now();
if (mousewheel === 0) {
$('.first').html('scroll fired first');
}
}
});
$('.container').on('mousewheel', function() {
$('.mousewheel').html('mousewheel fired: ' + ++mousewheel + ' times');
if (mousewheel === 1) {
firstMousewheel = Date.now();
if (scroll === 0) {
$('.first').html('mousewheel fired first');
}
}
if (firstMousewheel && firstScroll) {
if (firstMousewheel < firstScroll) {
$('.delay').html('scroll delayed by ' + (firstScroll - firstMousewheel) + ' ms');
} else {
$('.delay').html('mousewheel delayed by ' + (firstMousewheel - firstScroll) + ' ms');
}
}
});