I am working on how to show guides when moving boxes like it is in Google Docs Drawing. I would prefer an open-source code or any type of guide before starting writing my own.
- I do not need drag-n-drop across multiple browser windows so i don't need HTML5 Drag-n-Drop.
- Also i am using jquery-ui-draggable for boxes.
I have created a simple example with just borders line beside the draggable box. It shows up when we drag on the box. View demo here
HTML:
CSS:
JavaScript:
jquery ui has this already built in, see this demo: http://jqueryui.com/demos/draggable/#snap-to
if you insist on the guidlines you would maybe have to fork jqueryui or look at the source and see if you can extend it.
alternatively you could just add your own snapping-functions on top of jQuery ui, i've played with it for a bit, and while it doesn't seem like fun at least it also doesn't seem to be very hard.
you can view the example on jsfiddle: http://jsfiddle.net/x7uMh/103/ update: this works ~ jQuery 1.9 + jQueryUI 1.9. it breaks in newest jquery+ui. couldn't be bothered to see what exactly the problem is, typically its only minor problems though. just in case that site ever goes down, here's the code:
css
html
javascript (make sure to include jquery + jquery ui)
hope that helps, best, hansi.
I got an answer from this question: Javascript drag/drop - Illustrator style 'smart guides'
I think this is what are looking for. I also improved it by supporting the line for the same side. Here is the JsFiddle: http://jsfiddle.net/yusrilmaulidanraji/A6CpP/120/
HTML
CSS:
JS:
for those who still trying to find a way of doing this, i create a fiddle
i used snap and $(this).data('draggable').snapElements;
http://jsfiddle.net/j6zqN/1/