Properti transisi CSS
Contoh
Arahkan kursor ke elemen <div> untuk mengubah lebar secara bertahap dari 100 piksel menjadi 300 piksel:
div
{
width: 100px;
transition: width 2s;
}
div:hover {
width: 300px;
}
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Properti transition
adalah properti singkatan untuk:
Catatan: Selalu tentukan properti durasi transisi , jika tidak durasinya adalah 0, dan transisi tidak akan berpengaruh.
Nilai bawaan: | semua 0s memudahkan 0s |
---|---|
Diwarisi: | tidak |
Animasi: | tidak. Baca tentang animasi |
Versi: kapan: | CSS3 |
Sintaks JavaScript: | objek .style.transition="semua 2 detik" |
Dukungan Peramban
Angka-angka dalam tabel menentukan versi browser pertama yang sepenuhnya mendukung properti.
Angka yang diikuti oleh -webkit-, -moz- atau -o- menentukan versi pertama yang berfungsi dengan awalan.
Property | |||||
---|---|---|---|---|---|
transition | 26.0 4.0 -webkit- |
10.0 | 16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
Sintaks CSS
transition: property duration timing-function delay|initial|inherit;
Nilai properti
Value | Description |
---|---|
transition-property | Specifies the name of the CSS property the transition effect is for |
transition-duration | Specifies how many seconds or milliseconds the transition effect takes to complete |
transition-timing-function | Specifies the speed curve of the transition effect |
transition-delay | Defines when the transition effect will start |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Lebih Banyak Contoh
Contoh
Saat <input type="text"> mendapat fokus, ubah lebar secara bertahap dari 100px menjadi 250px:
input[type=text] {
width: 100px;
transition: width .35s ease-in-out;
}
input[type=text]:focus {
width: 250px;
}
Halaman Terkait
Tutorial CSS: Transisi CSS
Referensi DOM HTML: properti transisi