【发布时间】:2020-02-18 11:52:06
【问题描述】:
我目前正在构建一个交互式地图,我正在处理各种动画元素。然而,我注意到,动画在制作动画时会轻微跳跃/晃动。
你可以看到我的codepen here
有没有人知道为什么他们会轻微颤抖?我检查了所有浏览器,抖动很小但仍然有效!
@charset "UTF-8";
html,
body {
-webkit-text-size-adjust: 100%;
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
* {
box-sizing: border-box;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
outline: 0;
}
img {
max-width: 100%;
height: auto;
}
.map-container {
height: 100%;
width: 100%;
}
.map {
position: relative;
height: 100%;
width: 100%;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.desk-map {
position: relative;
overflow: hidden;
}
.animations>div {
position: absolute;
}
.balloon-1 {
width: 4.5%;
height: 9%;
background-image: url("https://www.ec-projects.co.uk/map/balloon-1.png");
background-repeat: no-repeat;
left: 12%;
top: 14%;
z-index: 1;
animation: balloon1 14s infinite linear;
}
@keyframes balloon1 {
0% {
left: 12%;
top: 14%;
}
50% {
left: 12%;
top: 2.5%;
}
20% {
left: 12%;
top: 14%;
}
}
.balloon-2 {
width: 4.5%;
height: 9%;
background-image: url("https://www.ec-projects.co.uk/map/balloon-2.png");
background-repeat: no-repeat;
left: 6.5%;
top: 21%;
z-index: 1;
animation: balloon2 14s infinite linear;
animation-delay: 1s;
}
@keyframes balloon2 {
0% {
left: 6.5%;
top: 21%;
}
50% {
left: 6.5%;
top: 15%;
}
20% {
left: 6.5%;
top: 21%;
}
}
.car-1 {
width: 1.5%;
height: 1.5%;
background-image: url(https://www.ec-projects.co.uk/map/car-1.png);
background-repeat: no-repeat;
right: 22%;
bottom: 32.25%;
z-index: 1;
animation: car1 30s infinite linear;
animation-delay: 1s;
-webkit-backface-visibility: hidden;
}
@keyframes car1 {
0% {
right: 22%;
bottom: 32.25%;
}
100% {
right: 57.25%;
bottom: -0.4%;
}
}
<div class="map-container">
<div class="map">
<div class="desk-map">
<img src="https://www.ec-projects.co.uk/map/map.png" />
<div class="animations">
<div class="balloon-1"></div>
<div class="balloon-2"></div>
<div class="car-1"></div>
</div>
</div>
</div>
</div>
【问题讨论】:
-
尝试在实时服务器上运行它,在 JavaScript 中有一个名为 live-server 的包