// element.style.:propertyName = propertyValue
element.style.setStyle('--variantName', variantValue)
element.style.:propertyName 하려고 console에 찍어보니 나오지 않아 당황했다.
style의 setStyle 함수를 이용하여 설정해주면 된다. 간단
box {
--rotation: 0;
transform: rotate(calc(var(--rotation) * 1deg));
}
const box = document.querySelctor('.box') // 방법1
// const box = document.getElementByClassName('box') // 방법2
box.style.setStyle('--rotation', 30)
[JS30] 자바스크립트로 CSS 변수(사용자 정의 속성) 조절하기
🔥Javascript 30 - Day 03🔥 1. 마크업/스타일링 이번에는 CSS를 JS로 제어해 봅시다! 우선 적당히 마크업하고 적당히 스타일링 합니다(참 쉽죠?). 자세한 html, css코드는 Codepen 결과물 에 있어요! > 제어
nykim.work
'A-HA💡 > CSS' 카테고리의 다른 글
[CSS] 그라데이션 종류 (0) | 2024.03.28 |
---|---|
[CSS] CSS, SASS, SCSS, LESS (0) | 2024.01.30 |
[CSS] 반응형 (1) | 2024.01.22 |
[CSS] 네이밍 (0) | 2023.11.07 |
[CSS] 형제 결합자 of 선택자 (0) | 2023.10.23 |