To achieve high performance when animating DOM elements, avoid animating top and left properties. Changing these properties forces the browser to recalculate layout (reflow), which is computationally expensive. Instead, use the transform property (e.g., translate), which avoids layout invalidation and can benefit from hardware acceleration.
If your animation requirements are simple, consider using native CSS animations or transitions instead of Tween.js to allow the browser to optimize the process.
// INEFFCIENT: Animating top/left causes layout reflow
const element = document.getElementById('myElement')
const tween = new TWEEN.Tween({top: 0, left: 0}).to({top: 100, left: 100}, 1000).onUpdate(function (object) {
element.style.top = object.top + 'px'
element.style.left = object.left + 'px'
})
// EFFICIENT: Animating transform avoids layout reflow
const element = document.getElementById('myElement')
const tween = new TWEEN.Tween({top: 0, left: 0}).to({top: 100, left: 100}, 1000).onUpdate(function (object) {
element.style.transform = 'translate(' + object.left + 'px, ' + object.top + 'px);'
})