I am looking for solutions how I can check whether a given element on a page is in viewport. There are a lot of ready-made solutions for Vue version 2 on the Internet, but I can't find something that would work in Vue 3. I can do it in Vanilla JS but I'm just learning the Vue 3 framework and I don't know how to do it right. Please help.
I am looking for solutions how I can check whether a given element on a page is in viewport. There are a lot of ready-made solutions for Vue version 2 on the Internet, but I can't find something that would work in Vue 3. I can do it in Vanilla JS but I'm just learning the Vue 3 framework and I don't know how to do it right. Please help.
Share Improve this question asked Jun 1, 2021 at 9:03 Grzyb9kGrzyb9k 1831 gold badge2 silver badges11 bronze badges 3 |1 Answer
Reset to default 21For Vue 3 there is this popular collection of essential Vue Composition Utilities called https://vueuse.org/. Is has the utilty https://vueuse.org/core/useElementVisibility/, that is (probably) what you are looking for. It comes with a great code example how to use it and a link to the source code so you can investigate how it is implemented.
v-on:ready
directive accomplished this without trouble in Vue 2. A little stumped at the dearth of both interest in and solutions to this question for Vue3. All solutions proposed here involve adding third-party utilities, polyfills, etc. It's a reactive framework ... why the need to add more stuff to get callbacks for such a basic thing as when an element (that is not a full component) is visible? – NFB Commented Oct 24, 2022 at 18:09