Answer the question
In order to leave comments, you need to log in
How to use scss variable in js?
Hello, I have a lot of scss constants and I need to set styles in js whose values are equal to scss constants. Is there a way to specify the value of the scss constant in js and not calculate it yourself ...
For example
$pi: 3.1415926535897932384626433832795;
document.getElementByID("el").style.opacity = " `require(scss).$pi` / 6 "
Answer the question
In order to leave comments, you need to log in
Not directly.
Just invented hack.
:root {
--test: 'Мегаполезная переменная которую нельзя просто запихнуть в js'
}
- css ( https://developer.mozilla.org/ru/docs/Web/CSS/:root ) stuff our constants. which we want to use further. document.querySelector(':root').attributeStyleMap.get('--test');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question