JavaScript
How to rotate image with JavaScript
January 04, 2023
1 min
The translate
function is a CSS transform function that allows you to move an element horizontally and vertically along the x-axis and y-axis. It takes two arguments, the x
and y
offsets, which specify the number of pixels to move the element horizontally and vertically.
For example, the following code will move an element 100 pixels to the right and 50 pixels down from its original position:
transform: translate(100px, 50px);
You can also use negative values for the x
and y
offsets to move the element left or up.
Here is an example of how you can use the translate
function in JavaScript to move an element:
// Get the element var element = document.getElementById('my-element'); // Move the element 100 pixels to the right and 50 pixels down element.style.transform = 'translate(100px, 50px)';