[英]Use CSS3 Animation to move div from top to bottom of screen?
我正在嘗試使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%;;
}
}
我以前從左到右制作過動畫,但是從上到下沒有動畫。 我已經在Google上進行了廣泛的搜索,但無濟於事。 謝謝
您可以嘗試以下操作:
.container{
background:lightblue;
height:1000px;
-webkit-animation: expand 5s;
}
@-webkit-keyframes expand{
0%{height:0px}
100%{height:1000px}
}
將bar的CSS更改為:
#bar {
position: absolute;
top: 0px;
left: 0px;
width: 5%;
background-color: #3b5598;
display: block;
-webkit-animation: all 7s ease;
}
然后使用一些Javacript將top更改為100%,margin-top更改為-height(您必須設置)
這應該很好地將欄從上移到下
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.