HTML DOM Style transition 속성은 HTML 문서에 있는 HTML 요소의 transition CSS 속성 값을 반환하고 수정합니다.
구문
다음은 구문입니다 -
1. 전환 전환
object.transition
2. 전환 수정
object.transition = “value”
여기서 값은 -
일 수 있습니다.| 값 | 설명 |
|---|---|
| 초기 | 이 속성 값을 기본값으로 설정합니다. |
| 상속 | 상위 요소에서 이 속성 값을 상속합니다. |
| 속성 지속 시간 타이밍 기능 지연 | 여기서 속성은 CSS 속성의 이름을 나타내며 transition.timing-function은 전환 효과의 속도 곡선을 나타냅니다. 지연은 전환 효과가 시작되는 시간을 나타냅니다. |
HTML DOM 스타일 전환 속성의 예를 살펴보겠습니다.
예시
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem 0;
}
.circle {
height: 100px;
width: 100px;
background-color: #db133a;
}
.circle:hover {
height: 200px;
width: 200px;
border-radius: 50%;
}
.show {
font-size: 1.2rem;
margin: 1rem 0;
}
</style>
<body>
<h1>DOM Style transition Property Demo</h1>
<div class='circle'></div>
<button onclick="set()" class="btn">Set Transition</button>
<div class="show">Now, hover on the square</div>
<script>
function set() {
document.querySelector('.circle').style.transition = "all 1s";
}
</script>
</body>
</html> 출력

"전환 설정을 클릭합니다. " 버튼을 누른 다음 "빨간색" 사각형에 마우스를 가져가면 전환 효과를 볼 수 있습니다.
