Feature detection for Native CSS Properties aka CSS Custom Variables
// Not too sure if it will trigger layout and paint for other CSS properties. | |
// I just use opacity which only triggers composite by default! | |
function hasNativeCSSProperties() { | |
const opacity = 1; | |
const el = document.body; | |
let hasNativeCSSProperties = false; | |
// Setup CSS properties. | |
el.style.setProperty('--test-opacity', opacity); | |
el.style.setProperty('opacity', 'var(--test-opacity)'); | |
// Feature detect then remove all set properties. | |
hasNativeCSSProperties = window.getComputedStyle(el).opacity == opacity; | |
el.style.setProperty('--test-opacity', ''); | |
el.style.opacity = ''; | |
return hasNativeCSSProperties; | |
} | |
hasNativeCSSProperties(); |
This comment has been minimized.
This comment has been minimized.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Thanks! My version: