HomeTutorsContact

How to move image or element with JavaScript

By Gulshan Saini
Published in JavaScript
January 04, 2023
1 min read

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)';

Tags

#javascript
Previous Article
How to rotate image with JavaScript

Related Posts

JavaScript
How to rotate image with JavaScript
January 04, 2023
1 min
Gulshan Saini

Gulshan Saini

Fullstack Developer

Topics

JavaScript
Angular
ReactJS
Typescript
Linux

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Quick Links

Contact UsBrowserCSSPythonPuppeteer

Social Media