I’ve created some test content using the Scrollspy plugin which detects when the user “enters” or “exits” visibility of an element. So far I’ve got it to display correctly when you scroll back up past the element, but results are flakey when you try to scroll up past the element and then scroll back down again. What’s doubly strange is that the example works absolutely fine on Codepen but doesn’t during local testing or when I upload to a test area on my webspace.
The expected behaviour is that the element should hide and reappear no matter which way you scroll. As per the console, on the Codepen example the console logs are correctly, while the webspace version doesn’t display an “EXIT” message when you scroll to the top again.
I agree, it seems that scrollSpy is just some sort of intersection observer wrapper so why use a plugin for something that can be done pretty much out of the box.
Thanks Paul!
I’ve got that example working but I can’t find a way to open it up to any elements with the “content” class - see example below: https://codepen.io/Shoxt3r/pen/oNgYXWe
In the meantime I’ve found a plugin called Scroll Reveal which encompasses the intersection and parameters to make it easier - demo here: https://scrollrevealjs.org/
The problem is that when you use querySelector you just get the one item but you need querySelectorAll to get all of them.
You would then need to iterate through that collection and apply appropriate rules to each.
Unfortunately I am only on a mobile and on holiday at the moment so hopefully one of the JS gurus on here (@James_Hibbard or others) can update the code for you.