반응형
자바 스크립트에서 CSS 변수에 액세스
이 질문에 이미 답변이 있습니다.
자바 스크립트에서 CSS 변수에 액세스하는 방법이 있습니까? 여기 내 CSS 변수 선언.
:root{
--color-font-general:#336699;
}
표준 방식 :
- 계산 된 스타일 얻기
getComputedStyle
getPropertyValue
원하는 속성의 값을 가져 오는 데 사용 합니다.
getComputedStyle(element).getPropertyValue('--color-font-general');
예:
var style = getComputedStyle(document.body);
console.log(style.getPropertyValue('--color-font-general'));
:root { --color-font-general: #336699; }
이것을 사용하십시오 :
window.getComputedStyle(document.documentElement).getPropertyValue('--color-font-general');
다음과 같이 변경할 수 있습니다.
document.documentElement.style.setProperty('--color-font-general', '#000');
참조 URL : https://stackoverflow.com/questions/41725725/access-css-variable-from-javascript
반응형
'your programing' 카테고리의 다른 글
isnan ()에 해당하는 Swift는 무엇입니까? (0) | 2020.12.29 |
---|---|
UITableView-Swift로 registerClass (0) | 2020.12.29 |
Google App Engine Flexible 환경의 가격, $ 500 강의 (0) | 2020.12.29 |
Androidx 프로젝트에서 Android 지원을 사용한 라이브러리를 사용할 수 있습니까? (0) | 2020.12.29 |
C #-공개적으로 상속 된 메서드를 숨길 수 있음 (예 : 파생 클래스에 대해 비공개로 설정) (0) | 2020.12.29 |