Closed danboyle8637 closed 3 years ago
Just messing around and so far I have found the observer will observe the
Any further updates on this? Still got the issue myself. I heard it was a Chrome-Based Bug and it seems to work on Firefox. Either this is an issue with Chrome or Interaction Observer. Need it for Lazy Loading the Image Elements in the SVG as they are CMS/Client Side and often rather large and it speeds up the site a lot to defer them.
@1sd15 I do have an implementation that works. But I have to look back to see if I can set it on the SVG.
Most of the time I am observing a wrapping section or div.
I will check it out and get back to you. Sorry for the late response.
Hi,
I'm facing the exact same issue. I'm trying to use Intersection Observer to delay animations on multiple elements inside an SVG. While IntersectionObserver is firing on the top level svg, it doesn't on the child level elements.
Any help would be appreciated, thanks.
What I have been doing is using another element to listen to with my observer. Usually I will listen to the main SVG element itself and then orchestrate the animations from there. Lately I have been using Framer Motion in my React apps and sites and it makes orchestrating these animations very easy.
hi!
I am an absolute beginner, so even though in theory i understand what you're saying, i won't be able to implement it :/
My question is, can i use either just the parent svg class to trigger the entire animation, or use a separate element altogether to trigger the animation?
What would the code look like for this? I am a beginner so i am having a tough time figuring this out. In layman terms, i want this: when x comes into view, trigger all the animations for Y.
Thanks
Sorry I am working on a project with a deadline of this weekend. I will show you how I built my intersection observer in Hugo. I think that is the closest to vanilla JS and HTML. I will make a video and also post some code on a CodeSandbox. Sorry but I am under a serious deadline.
@prat391 if you are working with basic HTML and javascript then I can send you a code snippet of how I achieved it for my project. I am very new to React so I won't be of much help. Drop a message if you want code snippet. That might help you.
@Sonny1314 would greatly appreciate it thanks!
I have also provided codePen link below. Hope it helps. So here is the basic layout of my code structure. I have pasted an SVG file inside my HTML document directly. You can use
below are the code snippets. HTML CODE ..inline css for filling svg elements and then comes picture of the svg elemets
MY CSS CLASSES FOR ANIMATION
JS CODE:
I have used window.addEventListener("load", function() {
so that everything is executed after the whole page loads.
Then coming to line 7 I have stored value of my section in which SVG is located in a variable called section.
I created a new intersection observer and Iam observing this section variable as you can see in line 30.
`var TreeLeft = document.getElementById("_3TreeLeft"); // left tree is element in my svg if(entries[0].intersectionRatio > 0){
TreeLeft.classList.toggle("slide-in-bck-bl-left-tree");
house.classList.toggle("slide-in-bck-bl-house");
TreeeRight.classList.toggle("slide-in-bck-bl-right-tree");
moon.classList.toggle("Moon");
}`
Now when the intersection ratio is more than one I select the element in SVG and toggle an animation class to it.
The CodePen link is below, make sure to switch to the sideView in CodePen to make viewport height big.
CODEPEN LINK: https://codepen.io/sonny1314/pen/GRovpEQ
Just to confirm the discussion thus far: chromium does not currently support observing an svg element other thant the top-level
https://bugs.chromium.org/p/chromium/issues/detail?id=963246
As this is not an issue with the spec text, I am closing this issue.
I saw an old issue in 2017 with Intersection Observer not working with SVG. I am still finding this to be the case.
When I setup my observer on an element of an SVG it immediately kicks off an entry even when the SVG isn't on screen yet.
And it never records any further entries or isIntersecting.
I am currently testing in Chrome.