I have a CSS file that contains a background image: in this case it's an animated PNG. This APNG has loop 1, meaning it only plays one time. I have it working that the file reloads but what I now need to have is to get the actual background url from the CSS File
FROM FILE: style.css
.my-div{
background-image: url("img/animation_menu_no_loop.png");
background-repeat: no-repeat;
pointer-events: none;
background-size: contain;
}
<div id="container" class="my-div">some text</div>
The following works fine and restarts the animation when in viewport:
document.getElementById('container').style.backgroundImage = 'url("img/animation_menu_no_loop.png'+'?a='+Math.random() +'")'
but there is only one problem, I have now hard coded the image src as I have taken from the CSS file. But if I update the CSS background I also need to update the 'style.background' line so for this I need to extract the actual URL used in the CSS file. How can I get that out?
I mean extract this section from the CSS file:
"img/animation_menu_no_loop.png"
background-image: url("img/animation_menu_no_loop.png");in the html and replacing the value each time the element comes into focus in the viewport, with the same value