【发布时间】:2021-11-29 19:25:34
【问题描述】:
我正在尝试在 CSS 中制作一个简单的动画,其中图像水平移动。在水平移动结束时(意思是最左边和最右边的点),我希望图像在垂直轴上翻转。我不希望图像在水平移动期间翻转;我只希望翻转发生在最左边和最右边。
这是我目前所拥有的:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="duck"></div>
</body>
</html>
.duck {
width: 100px;
height: 100px;
position: relative;
animation: duck 8s infinite;
}
@keyframes duck {
0% {
top: 20px;
left: 250px;
background: url("https://e7.pngegg.com/pngimages/644/738/png-clipart-yellow-duck-toy-plastic-duck-animals-ducks-thumbnail.png") no-repeat;
background-size: contain;
}
50% {
top: 20px;
left: 20px;
background: url("https://e7.pngegg.com/pngimages/644/738/png-clipart-yellow-duck-toy-plastic-duck-animals-ducks-thumbnail.png") no-repeat;
background-size: contain;
}
100% {
top: 20px;
left: 250px;
background: url("https://e7.pngegg.com/pngimages/644/738/png-clipart-yellow-duck-toy-plastic-duck-animals-ducks-thumbnail.png") no-repeat;
background-size: contain;
}
}
https://jsfiddle.net/vnu4hyxg/
如何进行翻转?
【问题讨论】:
标签: css css-animations