I have a site in which all sections take 100vh/vw, and I want to animate the opacity transition when user attempts to scroll up/down.
The thing is, the scroll event doesn’t fire because the window hasn’t really scrolled.
here’s the codepen, and the gist of it:
JavaScript
x
21
21
1
// css
2
.section {
3
width: 100vw;
4
height: 100vh;
5
opacity: 0;
6
transition: opacity 0.5s;
7
}
8
9
.section.active {
10
opacity: 1;
11
}
12
13
// html
14
<div className="section active">Some stuff here</div>
15
<div className="section">Some stuff here</div>
16
17
// js
18
window.addEventListener("scroll", () => {
19
console.log("never fires")
20
})
21
is this even possible?
And if not, any ideas for a workaround?
Advertisement
Answer
Change keyword scroll to wheel, this event fires when you try to scroll from mouse/pad(using fingers)even there is not scroll
JavaScript
1
4
1
window.addEventListener("wheel", () => {
2
console.log("event fires")
3
})
4