我正试着沿着抛物线(一个圆的25%)路径移动一个图像,有人能帮忙吗。 我已经多次尝试使用CSSTransform:rotate(18deg)translate(0px,100px)
来移动它,我的确切代码如下-
null
*{
margin: 0;
padding: 0;
}
.dash{
position: absolute;
top: 70%;
left: 40%;
width:50px;
height:50px;
background: #000;
animation: animate 5s linear infinite;
transform-origin: top;
}
@keyframes animate{
0%{
transform: rotate(0deg) translate(0px , 0px);
}
10%{
transform: rotate(-5deg) translate(0px,-50px);
}
20%{
transform: rotate(-15deg) translate(0px,-100px);
}
40%{
transform: rotate(-20deg) translate(0px,-150px);
}
60%{
transform: rotate(-30deg) translate(0px,-200px);
}
80%{
transform: rotate(-35deg) translate(0px,-250px);
}
100%{
transform: rotate(0deg) translate(0px,-300px);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div class="dash"></div>
</body>
</html>
null
您可以简单地执行如下操作:
null
* {
margin: 0;
padding: 0;
}
.dash {
position: absolute;
top: 0;
left: 0;
width: 50px;
height: 50px;
background: #000;
animation: animate 5s linear infinite alternate;
}
@keyframes animate {
0% {
transform: rotate(90deg) translate(200px);
}
100% {
transform: rotate(0deg) translate(200px);
}
}
<div class="dash"></div>