关键帧没有动画高度
Posted
技术标签:
【中文标题】关键帧没有动画高度【英文标题】:Keyframes not animating height 【发布时间】:2022-01-13 23:59:37 【问题描述】:我在我的 scss 中创建的关键帧应该为我的高度设置动画以使其成为 2s 动画,但它并没有这样做,而是高度只是立即变换,但同一关键帧中的宽度正在设置动画。
@import url("https://fonts.googleapis.com/css2?family=Maven+Pro:wght@500&family=Roboto&display=swap");
*
font-family: "Maven Pro", sans-serif;
color: white;
animation-delay: 1s;
body
width: 100%;
height: 100vh;
margin: 0%;
background-color: green;
display: flex;
justify-content: center;
align-items: flex-end;
overflow: hidden;
position: absolute;
bottom: 5%;
.swipe
animation-name: swipeWidthHeight, close;
animation-duration: 0.3s 2s;
animation-delay: 1s, 10s;
animation-fill-mode: forwards, forwards;
display: flex;
justify-content: center;
height: 179px;
width: 434px;
background-color: #fff;
.swipe .side
width: 180px;
height: 100%;
background-color: #fff;
display: flex;
justify-content: center;
animation-name: imageSize;
animation-fill-mode: forwards;
animation-duration: 0.3s;
.swipe .side img
width: 80%;
.swipe .center
position: relative;
animation-name: centerExpand;
animation-fill-mode: forwards;
animation-duration: 0.3s;
width: 74px;
height: 100%;
background-color: #38003c;
display: flex;
justify-content: center;
align-items: center;
.swipe .center .popup.firstHalf
opacity: 0;
position: absolute;
transform: translateX(-50%);
left: 50%;
width: 135px;
height: 35px;
background-color: white;
color: #38003c;
text-align: center;
font-family: "roboto";
font-size: 22px;
line-height: 35px;
font-weight: 500;
animation-name: firstHalf;
animation-delay: 2s;
animation-duration: 3s;
animation-fill-mode: forwards;
.swipe .center .popup.eaSports
opacity: 0;
position: absolute;
transform: translateX(-50%);
left: 50%;
width: 110px;
height: 76px;
background-color: #38003c;
color: #38003c;
display: flex;
align-items: center;
justify-content: center;
animation-name: firstHalf;
animation-delay: 4.8s;
animation-duration: 3s;
animation-fill-mode: forwards;
.swipe .center .popup.eaSports img
width: 61px;
.swipe .center .textContainer
font-weight: 400;
opacity: 0;
margin: 0% 2% 0% 2%;
height: 100%;
width: 100%;
.swipe .center .textContainer.left
text-align: right;
animation-delay: 1.15s;
animation-name: leftText;
animation-duration: 0.2s;
animation-fill-mode: forwards;
animation-timing-function: cubic-bezier(0.34, 0.58, 0.37, 1.48);
.swipe .center .textContainer.right
animation-name: rightText;
animation-delay: 1.15s;
animation-duration: 0.2s;
animation-fill-mode: forwards;
animation-timing-function: cubic-bezier(0.34, 0.58, 0.37, 1.48);
.swipe .center img
width: 44px;
@keyframes swipeWidthHeight
0%
height: 179px;
width: 434px;
100%
height: 77px;
width: 1064px;
@keyframes centerExpand
90%
justify-content: space-between;
100%
width: 1020px;
justify-content: space-between;
@keyframes rightText
0%
opacity: 1;
100%
padding-left: 10%;
opacity: 1;
@keyframes leftText
0%
opacity: 1;
100%
padding-right: 10%;
opacity: 1;
@keyframes imageSize
100%
height: 77px;
width: 77px;
@keyframes firstHalf
0%
opacity: 1;
bottom: 0%;
z-index: -1;
10%
z-index: -1;
opacity: 1;
bottom: 100%;
90%
z-index: -1;
opacity: 1;
bottom: 100%;
99%
z-index: -1;
opacity: 1;
bottom: 0%;
100%
z-index: -1;
opacity: 0;
bottom: 0%;
@keyframes close
100%
width: 1064px;
height: 77px;
bottom: -20%;
<body>
<div class="swipe">
<div class="left side">
<img src="https://cdn.discordapp.com/attachments/868038988437536768/918357217772732446/crest.svg" >
</div>
<div class="center">
<div class="firstHalf popup">First Half</div>
<div class="eaSports popup">
<img src="https://cdn.discordapp.com/attachments/868038988437536768/918357218003415080/ea-sports-logo.png" >
</div>
<div class="textContainer left">
<h1 class="text ">MANCHESTER CITY</h1>
</div>
<img src="https://cdn.discordapp.com/attachments/868038988437536768/918357218208907274/premier-league-icon.png" >
<div class="textContainer right">
<h1 class="text ">MANCHESTER CITY</h1>
</div>
</div>
<div class="right side">
<img src="https://cdn.discordapp.com/attachments/868038988437536768/918357217772732446/crest.svg" >
</div>
</div>
</body>
在代码笔中,“swipe”类和“swipeWidthHeight”的关键帧是存在高度问题的元素,没有动画。
如果整个项目为了更好地理解,下面是一个codepen https://codepen.io/charlieschuyler/pen/zYBZzZv
【问题讨论】:
【参考方案1】:缺少逗号:
.swipe
animation-name: swipeWidthHeight, close;
animation-duration: 0.3s, 2s; /* missing comma */
animation-delay: 1s, 10s;
animation-fill-mode: forwards, forwards;
display: flex;
justify-content: center;
height: 179px;
width: 434px;
background-color: #fff;
【讨论】:
一个简单的错误又让我失望了! 哈哈,有时会发生以上是关于关键帧没有动画高度的主要内容,如果未能解决你的问题,请参考以下文章