gpt4 book ai didi

html - 使用css动画让div元素移动到页面的每个 Angular 落

转载 作者:行者123 更新时间:2023-12-03 13:58:44 25 4
gpt4 key购买 nike

我想知道如何使用css动画使圆形div元素到达页面的每个 Angular 落。我试图这样做无济于事。
相当基本的问题,但它会帮助我理解。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS 201</title>
<link href="https://fonts.googleapis.com/css2?family=Pacifico&display=swap" rel="stylesheet">
<style>
.box {
width: 300px;
height: 300px;
border: 10px solid black;
background-color: black;
border-radius: 50%;
position: absolute;
top: 0;
left: 0;
animation: myAnimation 4s infinite alternate,myAnimation2 4s infinite alternate;
}
@keyframes myAnimation {
0% { top: 0; left: 0; }
30% { top: 3000px; }
68%, 72% { left: 50px; }
100% { top: 3000px; left: 90%; }
}

@keyframes myAnimation2{
0% { bottom: 0; right: 0; }
30% { top: 3000px; }
68%, 72% { left: 50px; }
100% { top: 3000px; left: 90%; }
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>

最佳答案

CSS 更改

.box {
width: 300px;
height: 300px;
border: 10px solid black;
background-color: black;
border-radius: 50%;
position: absolute;
top: 0;
left: 0;

animation: myAnimation 4s infinite;

}
@keyframes myAnimation {
5% { top: 0; left: 0; }
25% { top: 200px; left: 0px; }
50% { top: 200px; left: calc(100% - 320px); }
75% { top: 0px; left: calc(100% - 320px); }
100% { top: 0px; left: 0; }
}
<div class="box"></div>

关于html - 使用css动画让div元素移动到页面的每个 Angular 落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66812538/

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