Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Draggable AND Resizable

Tags:

function makeResourceDrag(arrIndexID) {      $('#imgA' + arrIndexID).resizable();      $('#imgA' + arrIndexID).draggable({         start: function(event, ui) {             isDraggingMedia = true;         },         stop: function(event, ui) {             isDraggingMedia = false;              // Set new x and y             resourceData[arrIndexID][4] = Math.round($('#imgA' + arrIndexID).position().left / currentScale);             resourceData[arrIndexID][5] = Math.round($('#imgA' + arrIndexID).position().top / currentScale);          }     });  } 

This works fine if the resizeable line is taken out, but I want these images to be draggable and resizeable, I get funny behaviours if I try and make the same element have both attributes, does anyone know a way to make this work?

Thanks!

like image 877
Tom Gullen Avatar asked Feb 09 '11 17:02

Tom Gullen


People also ask

What is jQuery draggable?

Draggable() Method This method allows the elements to be dragged with the help of mouse. Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port.

Does jQuery draggable work on mobile?

jQuery UI wasn't originally written to handle mobile devices. It won't even play nicely with jQuery Mobile. some parts of it may still work well in mobile devices, but anything that has anything to do with dragging will fail.


1 Answers

Looks like it's because you're doing it on an <img>, which jqueryui wraps in a <div>, and then the draggable component of the image happens within the wrapping <div>.

Try wrapping the <img> in a <div> (which if styled display:inline-block, will "hug" the size of the image in both x and y axes), make the <div> draggable (and therefore the enclosed <img> will be as well), and make the <img> resizable (and since the div hugs the image, it all sits nicely).

Working example: http://jsfiddle.net/vrUgs/2/

like image 135
davin Avatar answered Oct 14 '22 06:10

davin