[英]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.