Im trying to develop a small page that has the following functionality:
- Page will have two divs: one being #origin, containing a lot of thumbnail images, and the second one will be #drop, where the images can be dropped on (up to 3 only).
- it needs to be possible to drag-drop the images from #drop back to origin.
- #drop needs to be sortable, since the order of the 3 selected images matter.
- When dropped on #drop, the images should align, as if they had original been displayed like that from the start.
I had never used jQuery before, and I even had a working page prototype before, where I already had the drag and drop between two containers through native HTML5 drag and drop events, but when I added the sortable() jquery functionality to #drop, the images could no longer be dragged back to #origin, which breaks my functionality.
So, I started over and wanted to implement both the drag & drop functionality as well as the sortable with jQuery. I've read pretty much the whole API for all draggable, droppable and sortable functionality, but I'm having trouble getting this to work. Not sure if it's the settings I'm using for each functionality.
On the fiddle, you can see that the images become draggable and I can see the settings I specify in effect (opacity, cursor), but the images cant be dropped on #drop.
From what I understand, the combination of making images draggable, the images having a "draggable" class, and making #drop droppable with an accepts of ".draggable", it should allow the most basic functionality, but even that doesn't seem to take. Also I read that if both draggable and droppable have the same "scope" setting, it should also work, but it isn't.
Here's a simple version of the page's code, plus a jsFiddle: http://jsfiddle.net/39khs/
Code:
css:
#origin {
background-color: green;
}
#drop {
background-color: red;
min-height: 120px;
}
js:
$("img").draggable({ helper: "clone", opacity: 0.5, cursor: "crosshair", scope: "drop" });
$("#drop").droppable({ accept: ".draggable", scope: "drop"});
$("#drop").sortable();
html:
<div id="wrapper">
<div id="origin" class="fbox">
<img src="http://placehold.it/140x100" id="one" title="one" class="draggable" />
<img src="http://placehold.it/140x100" id="two" title="two" class="draggable" />
<img src="http://placehold.it/140x100" id="three" title="three" class="draggable" />
</div>
<p>test</p>
<div id="drop" class="fbox">
</div>
</div>
Any help is greatly appreciated.