Make the image draggable, but fit exactly parental restraint

I want to know how to work with the new facebook framework using jquery?

this example is like dragging and dropping a facebook image, but it does not work with image size limitation: http://oneblackbear.com/draggable/index.html

I want the same facebook image reset code.

thanks

+4
source share
1 answer

Try this demo!

$(".image_drag img").draggable({ stop: function(ev, ui) { var hel = ui.helper, pos = ui.position; //horizontal var h = -(hel.outerHeight() - $(hel).parent().outerHeight()); if (pos.top >= 0) { hel.animate({ top: 0 }); } else if (pos.top <= h) { hel.animate({ top: h }); } // vertical var v = -(hel.outerWidth() - $(hel).parent().outerWidth()); if (pos.left >= 0) { hel.animate({ left: 0 }); } else if (pos.left <= v) { hel.animate({ left: v }); } } }); 

Or you can manually set the containment for your element:

jsBin demo

 $("img").draggable({ containment: [-99, -119, 0, 0], scroll: false }); 
+5
source

Source: https://habr.com/ru/post/1403206/


All Articles