你可以嘗試使用JavaScript來一個className
添加到您div
這樣的:
function grow() {
var element = document.getElementById("boxid");
if (!element.className) {
element.className = 'tall';
} else {
element.className = '';
}
};
我已經添加了className
的廢止,使動畫的切換。
然後,讓CSS處理做的所有轉化爲你:
#boxid {
background-color: red;
width: 50px;
height: 50px;
position: relative;
-webkit-transition: height 0.3s ease;
transition: height 0.3s ease;
}
#boxid.tall {
height: 500px;
-webkit-transition: height 0.3s ease;
transition: height 0.3s ease;
transform: translate3d(100) /* this property ensures GPU processing cross-browser */
}
Codepen例子是here。
關於平滑CSS過渡的好文章是here。
有關跨瀏覽器使用translate3d
的一些問題記錄在here。
Choppiness對我來說看起來是一樣的,瀏覽器到瀏覽器。嘗試將所有轉換移動到CSS。 – jacefarm