我正在尝试使用Css动画创建位置类型动画,其中 location div 在 line div 上标记的兴趣点上进行动画处理。我的第一个兴趣点是 line div 的中心。但是,以下代码似乎并没有满足我的要求。
top: 116px;
left: 50%;
transform: translate(-50%, -50%);
.location {
position: absolute;
top: 116px;
left: 50%;
transform: translate(-50%, -50%);
width: 120px;
height: 120px;
border-radius: 50%;
border: 16px solid #f3f3f3;
border-top: 16px solid #3498db;
border-bottom: 16px solid #3498db;
animation: Location 4s linear infinite;
}
@keyframes Location {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.line {
position: absolute;
top: 100px;
left: 50%;
transform: translateX(-50%);
border: 8px solid #f3f3f3;
width: 500px;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div class="location"></div>
<div class="line"></div>
</body>
</html>
答案 0 :(得分:1)
像这样?您还应该在动画中添加translate(-50%,-50%)
。否则,它将删除translate(-50%,-50%)
并覆盖它。
.location {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 120px;
height: 120px;
border-radius: 50%;
border: 16px solid #f3f3f3;
border-top: 16px solid #3498db;
border-bottom: 16px solid #3498db;
animation: Location 4s linear infinite;
}
@keyframes Location {
0% {
transform:translate(-50%, -50%) rotate(0deg);
}
100% {
transform:translate(-50%, -50%) rotate(360deg);
}
}
.line {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 8px solid #f3f3f3;
width: 500px;
}
<div class="location"></div>
<div class="line"></div>