[英]how to animate width and height 100% using css3 animations?
我有以下代碼
HTML
<div></div>
css
div {
background: tomato;
width: 100px;
height: 100px;
-webkit-animation: animateThis 0.3s ease-in;
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes animateThis {
0% {
width: 100px;
height: 100px;
}
100% {
width: 100%;
height: 100%;
}
}
我想要做的是我想將 div 和高度放大到 100% 以覆蓋整個瀏覽器。 我不知道如何設置 100% 高度的動畫。 我在谷歌上搜索了一下。 沒有找到運氣
你需要指定 100% 的東西..在這種情況下, html/body
* { margin: 0; padding: 0; } html, body { height: 100%; } div { background: tomato; width: 100px; height: 100px; -webkit-animation: animateThis 1s ease-in; -webkit-animation-fill-mode: forwards; } @-webkit-keyframes animateThis { 0% { width: 100px; height: 100px; } 100% { width: 100%; height: 100%; } }
<div></div>
您還需要將html
和body
標簽設置為100%
以欺騙瀏覽器。
* { margin: 0; padding: 0; } html, body { height: 100%; } div { background: tomato; width: 100px; height: 100px; -webkit-animation: animateThis 0.3s ease-in; -webkit-animation-fill-mode: forwards; } @-webkit-keyframes animateThis { 0% { width: 100px; height: 100px; } 100% { width: 100%; height: 100%; } }
<div></div>
.mydiv {
animation-name: test-animation;
animation-duration: 1s;
}
@keyframes test-animation {
from {
width:0px;
}
to {
width:calc( 100% - 1px );
}
}
這是一個很好的選擇,通過使用 calc() 函數從 0px 動畫到幾乎 100%,該函數將返回幾乎 100% 的寬度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.