Firstly please no jQuery. I could do this in jQuery etc., the point of the question is to do it without unnecessary dependencies.
The scenario here is I'm creating a single page website with several sections to scroll through. I want to use Vue.js's transitions to simply fade in once the browser has scrolled to that section. I've managed to make the transitions work with the appear attribute but the problem is this initial render trigger works on elements that are off screen and I want to defer that trigger until when the browser has scroll the element on screen.
I've found a library like vue-observe-visibility which would kind of works for what I need but honestly I don't want to create a load of data properties simply for the trigger to change it to true for a v-if statement to trigger the fade in effect. Hopefully that makes some sense.
one way, using directives, would be have an on-scroll listener. when the element is in view, then add a class that transitions opacity to 1 (or x-offset). Then once it's in view, destroy the listener.
This makes is easy to add to elements, as you don't need to manage state for each item, just change
<div>
to<div class="hidden hidden-left" v-infocus="'showElement'">
, for every object you want to do this for.... only, I wish I could remove the listener when the component is unmounted. I think in a SPA this could cause some listeners to stick around.