I’m loading in a Spline Scene via the Spline Scene element inside Webflow. It’s rendered as a canvas in the html. Is there a way to listen for when the scene is loaded?
I found this info but that is not working because Webflow is not using the
Make sure you run your scripts after the target div has been placed in the DOM (such as placing the spline code at the end of your <body> tag. Then, it’s just a matter of listening for that event:
No official scene load event in Webflow for Spline yet, bummer! I’ve seen some folks using setInterval to check for specific elements within the scene appearing, which might indicate it’s loaded. Not ideal, but could be a workaround.
Annnnd… EUREKA: Just use the code below, and you will receive the load event.
<script>
document.querySelector("#spline-bg").addEventListener("w-spline-load",(e)=>{
console.log("Spline scene loaded through Webflow",e)
})
</script>
Man I love reverse engineering minified code, such a fun puzzle
Sure, but yes, it was all reverse engineering, no docs or anything:
Basically, first I identified the custom attributes that webflow outputs in the source code of the website. (Basically, using view-source:{{URL_HERE}} → view-source is used so no scripts alter the page). I paid close attention to the attributes on the spline animation element.
Then, after identifying those attributes, I basically openend the .webflow.js file that webflow ships on your sites and searched for those attributes. From there, it was just a matter of reading the minified code around those attributes.