I'm trying to build a project in which the user can click on an image and then an interactive .svg is loaded (inside an object tag). For that, I need to track the mouse movement on the entire screen (not only the .svg) after the loading has happened.
However, neither document.addEventListener nor window.addEventListener seem to work on the .svg. They just work outside its boundaries. Is there a way to fix this without having to combine document.addEventListener and the specific interactiveSVG.addEventListener?
Here is my code (edited):
let firstImage = document.querySelector('#my-first-img');
let objectSVG = document.querySelector('#svg-obj');
let interactiveSVG;
firstImage.addEventListener('click', e => {
objectSVG.data = `mySVG.svg`;
objectSVG.addEventListener('load', e => {
interactiveSVG = objectSVG.getSVGDocument();
document.addEventListener('mousemove', e => {
console.log(e.clientX);
});
});
});