Accessing css variable in JS file
问题 I am having a CSS file which has some variable define @red: red-color @yello: yellow-color .... I can use this variable in CSS file, But I want to know how can I access them in my JS file. 回答1: Assuming you're using native CSS variables and not some preprocessor, take a look at this page. At the bottom there's a section called Values in JavaScript which describes how to access native CSS vars in JS code. getComputedStyle(element).getPropertyValue("--my-var"); However if you are using a CSS