DEV Community

Jonas Grøndahl
Jonas Grøndahl

Posted on

2 1

Implement dragging and resizing in JS

Recently I decided to implement dragging and resizing of an object using vanilla JavaScript. I think many people use libraries to handle this type of functionality since it's easy and it works.

Well anyway, if you want to have a look at how it's implemented from scratch, I made a short 2-part YouTube video series. In part 1 we make a div shaped as a square movable and in part 2 we extend the implementation and make it re-sizable in 4 different directions!

You'll realize the implementation of the two is similar since we are interested in the x and y coords of the mouse at the start of holding mouse button down and as we move it.

Here's the video:

JavaScript

If you have any comments on the code, I'd love to hear them.

Note: Not super experienced uploading stuff to YouTube and speaking on video, so definitely some areas that could use some improvement 🐼

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

Retry later
Retry later