var clamp = function(val, min, max) {
return Math.min(Math.max(val, min), max);
}
// ...
// new position tank
this.pos = function () {
this.x += this.stepX;
this.y += this.stepY;
this.x = clamp(this.x, 0, canvas.width);
this.y = clamp(this.y, 0, canvas.height);
}
/* ПЛОХО */
.my-div {
background-size: cover;
}
/* ЛУЧШЕ */
.my-div::before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-size: cover;
will-change: transform;
z-index: -1;
}
top
нужно менять свойство translate
. В этом случае при анимации будет задействована видеокарта и она будет сильно плавнее. opacity: 0;
, а под него подложить div с нужной графикой