I'm looking for a way to implement Adobe Illustrator style 'smart guides' when dragging/dropping in Javascript. I'm currently using jQuery UI's draggable
:
$('.object').draggable({
containment: 'parent',
snap: '.other-objects',
snapTolerance: 5
})
This does 90% of what I want - I can drag .object
around within it's parent, and it will snap it's edges to .other-objects
when it gets close enough.
What I want, however, is for a line of some kind (or a guide of some kind) to appear, if it's in line with the edge of another object, so I can snap stuff in a row without them being directly next to each other.
Does anybody know if this is possible, or how I'd go about doing it?
I started messing around with a jsFiddle. It's not perfect, but it should get you started.
The bulk of the logic is within jQuery UI's drag event handler:
If I have some time later I'll come back and give it some more thought, but figured you'd appreciate a semi-answer so start you off for now =)
I added smart guides functionality to draggable and resizable plugins.
You can see how it works:
jsFiddle: https://jsfiddle.net/chukanov/bypr7Lt3/2/
github: https://github.com/aichukanov/smartguides
demo-site: https://ready2.net/smartguides.shtml
you can try to create a plugin like this
and use it like this
http://jsfiddle.net/Vd5X6/
I forked the JSFiddle from above, and I improved it by supporting the same side of shaped. Here is the JsFiddle: http://jsfiddle.net/yusrilmaulidanraji/A6CpP/120/
HTML:
CSS:
JS:
I forked the fiddle above, added support for midlines.
This way it would be easier to align elements in a row/column.
Check the fiddle below:
http://jsfiddle.net/elin/A6CpP/
Whats the problem for my jsfiddle
Visit jsfiddle.net/datakolay/7xzTn/