animation-iteration-count: 1;
似乎没有用,汽车只是消失了。任何人都可以帮助我吗?
CSS:
.car {
animation-duration: 8s;
animation-fill-mode: forwards;
animation-iteration-count: infinite;
animation-name: FloatCar;
animation-timing-function: linear;
background-repeat: no-repeat;
background-size: auto 100%;
height: 70px;
left: 100%;
position: absolute;
width: 100%;
z-index: 1;
}
.carStop {
animation-iteration-count: 1;
}
@keyframes FloatCar {
from {
transform: translateX(-130%) translateZ(0)
}
;
to {
transform: translateX(100%) translateZ(0)
}
;
}
使用Javascript:
function stopCars () {
var allCars = document.querySelectorAll('.car')
for (var item of allCars) {
item.className += ' carStop'
}
}