【发布时间】:2013-10-09 08:52:43
【问题描述】:
我试图让一个 div 从页面顶部扩展到底部。当动画开始时,div 将被隐藏(高度 0%),直到它以 100% 填充页面。我试图这样做,但似乎都没有工作:
HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>About Me</title>
<link rel="stylesheet" href="stylesheets/main.css">
</head>
<body>
<div id="bar"></div>
</body>
</html>
CSS:
*
{
box-sizing: border-box;
}
body
{
height: auto;
width: auto;
direction: ltr;
z-index: 1;
background-color: #fff;
}
#bar
{
position: relative;
top: 0px;
left: 0px;
width: 5%;
background-color: #3b5598;
display: block;
-webkit-animation: bar 7s ease;
}
@keyframes bar
{
0% {
top: 0%;
}
100% {
top: 100%;;
}
}
我之前有动画从左到右工作,但从上到下没有任何效果。我已经广泛地用谷歌搜索了这个但无济于事。谢谢
【问题讨论】:
-
动画
top属性将平移元素,如果你想扩大,动画height或bottom属性。此外,关键帧确实适用于更复杂的动画,当从一种状态切换到另一种状态时,您可以使用transition,它会有更好的浏览器支持。 -
使用 jQuery 非常快:
$("#bar").animate({"height":"500px"}, 3000);参考:api.jquery.com/animate