I am looking for a JS solution that will
- return true while the user is scrolling and
- false as soon as the user stops scrolling
I have looked at this similar question, but rather than checking if the user is scrolling it will just set a variable after scrolling and you have to manually manage the state before and after.
userHasScrolled = false;
window.onscroll = function (e) { userHasScrolled = true; }
I'd rather see a function that checks on call if the user is currently scrolling. Something like below. But I can't figure out how to do that with the onscroll event, or if it's possible at all.
items.forEach(item => {
item.addEventListener('mouseenter', () => showItem());
});
function userIsScrolling() {
// check if user is currently scrolling
if () {
return true
} else {
return false
}
}
function showItem() {
if (!userIsScrolling()) {
// if user is not scrolling, execute function logic
}
}
PS: Might make more sense to check userIsScrolling before adding the eventListener. But then we also need to think about logic to remove the eventListener. Open for suggestions on this.