Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

คุณสมบัติ CSS Transition (Shorthand)

ใช้คุณสมบัติ CSS transition เพื่อกำหนด transition properties ทั้ง 4 ค่าในบรรทัดเดียว คุณสามารถลองรันโค้ดด้านล่างเพื่อทดสอบ transition property:

ตัวอย่างโค้ด

<!DOCTYPE html>
<html>
<head>
  <style>
    div {
      width: 150px;
      height: 150px;
      background: blue;
      transition: height 3s;
    }
    div:hover {
      height: 250px;
    }
  </style>
</head>
<body>
  <h1>Heading One</h1>
  <p>Hover เมาส์ที่กล่องด้านล่างเพื่อเปลี่ยนความสูง:</p>
  <div></div>
</body>
</html>

รูปแบบ Shorthand: transition: property duration timing-function delay;

  • property - คุณสมบัติที่จะ transition (หรือ all)
  • duration - ระยะเวลา (บังคับ)
  • timing-function - โค้งความเร็ว (optional, default ease)
  • delay - หน่วงเวลา (optional, default 0s)

ตัวอย่าง: transition: width 2s ease-in 1s, height 1s linear;