Is it possible to dynamically set a scale and margin for an element in order to center it fluidly using the wheel event? I am aiming to achieve a smooth transition while also adjusting scroll position on the wrapping element in a fluid manner.
In the provided jsfiddle example, I have utilized the CSS transition attribute to create a fluid effect. However, there seems to be an issue where the margin animation triggers faster than the scale adjustment, causing the div to initially move sideways. This can be observed especially when zooming in with greater intensity. How can this be rectified so that the cross located in the middle of the image does not shift sideways during zoom in and out?
To view the problem clearly, simply use the mouse scroll once and then repeat the action at the end of the animation.
To address this issue, I followed Gabriele Petrioli's solution but still required further information regarding the positioning of the element. As a result, I decided to integrate the margins into the CSS transform attribute through the 'translate' option, which appears to be functioning correctly.
I made the following modification:
$el.css({
'transform': "translate(" + t + "px, " + l + "px) scale(" + scale + ")",
});
For more insight, you can refer to the updated jsfiddle.