'Apply style to images before they are loaded
Particularly I am interested in applying style for images and background images. The style is injected with a CSS class into the page from a chrome extension. I have no direct control over elements on the page but only through my js script which is injected into webpage when it is open. The class that is applied to every element before the page is loaded with DOMContentLoaded
event listener is smth like that:
function insertClass(){
//find all elements with img tag or background style
//add style to those elements
}
document.addEventListener('DOMContentLoaded', insertClass})
Eventhough, according to the description of DOMContentLoaded
the function should run before the element is loaded, I still have a visual of images without the style applied for a split second, meaning that style is applied after the image is rendered. Is there a way to apply style before the image is rendered?
Solution 1:[1]
maybe it is just a typo, but there is an extra }
in document.addEventListener('DOMContentLoaded', insertClass})
, after insertClass
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | oooOOO000m000OOOooo |