I have implemented a small plugin that does what you want. It can provide protection after resizing the dragged file, and even works when you are in the middle of the drag and drop. I tested it with jQuery UI 1.8.6 and jQuery 1.4.3, but it may break with past or future versions as it must use internal methods.
Working demo
http://jsbin.com/uvino4/27
Full source code
Plugin
(function ($){ var $window = $(window);
HTML demo
<!DOCTYPE html> <html> <head> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script> <meta charset=utf-8 /> <title>JS Bin</title> <style> #container { width: 20em; height: 20em; border: 0.5em solid black; } .draggable { width: 5em; height: 5em; border: 0.2em solid black; position: absolute; } #one { background-color: #F55; } #two { background-color: #5F5; } </style> </head> <body> <div id="container"> <div class="draggable" id="one">drag me</div> <div class="draggable" id="two">drag me</div> </div> </body> </html>
JavaScript demo
var draggables = $('.draggable'); draggables.draggable({containment: 'parent', stack: draggables}); var resizeDraggables = function (){ draggables. each(function (){ var size = 5 + Math.random() * 5; size = size.toString() + "em"; $(this).css({width: size, height: size}); }). draggable("refreshContainment"); }; resizeDraggables(); setInterval(resizeDraggables, 2000);
brianpeiris
source share