I set out to find the bare minimum requirements for making draggable elements with jQuery UI. It turns out the minimum is actually very little!
The above code gives us the following:
So did it work?
Yes, it did! Don’t believe me? Go ahead and drag Things 1, 2, and 3 around above. You probably noticed that this implementation leaves a lot to be desired, such as:
- How is the user supposed to know that Things 1, 2, and 3 are draggable? They would never know unless they happened to try it.
- Without some sort of structure and a well-defined place to drag the Things to, it all seems pretty random. The Things can be dragged anywhere they want without any constraints and without any purpose.
- In the middle of dragging, the Things trigger the scrollbar at the bottom of the document, even if they are nowhere near the edge.
But hey…it’s draggable, right?
To all of these points I say…this is what you get when you seek the bare minimum! Nonetheless, there is a lot to be learned by seeking the minimal working setup when trying out different types of code and code libraries.
There are many ways to customize the experience and solve these basic problems, but hopefully this illustrates the core concept and how simple it actually is to implement.