คุณสมบัติ TransitionProperty ของ HTML DOM จะส่งคืนและแก้ไขชื่อของคุณสมบัติ CSS ขององค์ประกอบที่เอฟเฟกต์การเปลี่ยนแปลงมีไว้สำหรับในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
1. กลับ TransitionProperty
object.transitionProperty
2. การปรับเปลี่ยน TransitionProperty
object.transitionProperty = “value”
ค่านี้สามารถเป็น −
| ค่า | คำอธิบาย |
|---|---|
| เริ่มต้น | ตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| สืบทอด | รับค่าคุณสมบัตินี้จากองค์ประกอบหลัก |
| ทั้งหมด | ตั้งค่าเอฟเฟกต์การเปลี่ยนแปลงในทุกคุณสมบัติ |
| ทรัพย์สิน | แสดงถึงรายการคุณสมบัติ CSS |
| ไม่มี | ไม่เลือกคุณสมบัติ |
ให้เราดูตัวอย่างของ HTML DOM Style TransitionProperty Property:
ตัวอย่าง
<!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%;
transition: all 1s;
}
.show {
font-size: 1.2rem;
margin: 1rem 0;
}
</style>
<body>
<h1>DOM Style transitionProperty Property Demo</h1>
<div class='circle'></div>
<button onclick="set()" class="btn">Change TransitionProperty</button>
<div class="show">Now, hover on the square</div>
<script>
function set() {
document.querySelector('.circle').style.transitionProperty = "border-radius";
}
</script>
</body>
</html> ผลลัพธ์

คลิกที่ “เปลี่ยน TransitionProperty ” แล้ววางเมาส์เหนือปุ่ม “สีแดง ” สี่เหลี่ยมเพื่อดูเอฟเฟกต์ TransitionProperty
