gpt4 book ai didi

html - 带有CSS动画的元素方向控制

转载 作者:太空宇宙 更新时间:2023-11-04 09:03:50 26 4
gpt4 key购买 nike

我有 3 只带有 css 动画的鸟。目前所有三只鸟都直线进入 Canvas ,但鸟不会像这样飞。图片中清楚地描述了我想要实现的目标。我想控制鸟在 Canvas 上旅行的每个阶段的飞行方向。任何人都可以帮助我实现它吗?

Flying Direction

Result after coming in to the canvas

我的代码

HTML

<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="canvas">
<img class="people" src="https://i.imgsafe.org/9967e45cc8.png" alt="">
<img class="bird-1" src="https://i.imgsafe.org/996ac926a0.png" alt="">
<img class="bird-2" src="https://i.imgsafe.org/996bc03236.png" alt="">
<img class="bird-3" src="https://i.imgsafe.org/996cfb24a4.png" alt="">
</div>
</body>
</html>

CSS

body{
margin: 0;
}

.canvas{
background-color: lightgrey;
width: 300px;
height: 250px;
position: relative;
left: 30%;
top: 20%;
overflow: hidden;
}

.logo,
.people{
position: absolute;
}


.bird-1{
position: absolute;
width: 50px;
-webkit-animation: first 2s linear forwards;
animation: first 2s linear forwards;
top: -70px;
left: 55px;
}

.bird-2{
position: absolute;
width: 50px;
-webkit-animation: second 2s linear forwards;
animation: second 2s linear forwards;
top: 165px;
left: -50px;
}
.bird-3{
position: absolute;
width: 50px;
-webkit-animation: third 2s linear forwards;
animation: third 2s linear forwards;
top: 163px;
right: -50px;
transform: rotateY(180deg);
}

@-webkit-keyframes first{
0%{top: -70px;}
100%{top:65px;}
}

@-webkit-keyframes second{
0%{left: -50px;}
100%{left:15px;}
}

@-webkit-keyframes third{
0%{right: -50px;}
100%{right:135px;}
}

My PEN

最佳答案

您必须以特定速度(使用曲线)在 X 轴上创建运动,并以另一种速度创建 Y 轴运动。您可以查看本教程,它应该为您提供在 CSS 中执行此操作所需的一切: http://tobiasahlin.com/blog/curved-path-animations-in-css/

您还可以为每只鸟创建一个 SVG 路径并使用此技术,但它需要 JavaScript:http://icanbecreative.com/article/animate-element-along-svg-path/

关于html - 带有CSS动画的元素方向控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42583918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com