Drag and Drop and jQuery
I'm using a开发者_如何学Gojax to populate some thumbnails for search results, and I'd like to make them draggable and droppable. I have a two part question. I want behavior like that in HTML5, where you can only drag the object to specific bins, or it will just snap back to where it was. Is there a way to do that in the jQuery droppable thing? My other question is, since I'm dynamically loading new content into the page, do I need to do anything special with setting attributes to get drag and drop to work? I'm still learning jQuery and javascript, and all the examples I've seen are of static elements.
Look at jquery ui, drag and drop is very possible and customizable using jquery ui. http://jqueryui.com/demos/draggable/ and http://jqueryui.com/demos/droppable/
Yes, you can define "draggable" and "droppable" objects using jQuery UI where an object will revert back to it's previous position if not dropped on a predefined object. http://jqueryui.com/demos/droppable/#revert should be a helpful resource for you.
As for your second question, yes, you will need to call the draggable()/droppable() methods on your dynamically created objects to give them those respective properties. I created a basic fiddle at http://jsfiddle.net/947u6/5/ that provides an example of creating a new object, making it draggable and adding it to an existing set. I'm sure your application is much more advanced, but I think it make the point.
精彩评论