Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Simple solution (see <a href="http://jsfiddle.net/ek8Fc/5/">DEMO</a>):</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; #parent { height: 300px; width: 300px; border: 1px black solid; position: relative; left: 0; } #images { height: 100px; width: 100px; background-color:orange; } &lt;/style&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"&gt;&lt;/script&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="parent"&gt; &lt;div class="container"&gt; &lt;div id="images"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;script&gt; $(document).ready(function() { var $document = $(document), $parent = $("#parent"), $container = $(".container", $parent), offset = $container.offset(), scrollbarSafety = 15; // use this to avoid dragging outside of window, thus creating scrollbars and wreaking all kinds of havoc on draggables containment checks $container .width($document.width() - offset.left - scrollbarSafety) .height($document.height() - offset.top - scrollbarSafety); $("#images") .draggable( { containment: $container, drag: function(event, ui) { var $draggee = $(this), draggeePosition = $draggee.position(), shouldWidth = draggeePosition.left + $draggee.width(), shouldHeight = draggeePosition.top + $draggee.height(); if($parent.width() &lt; shouldWidth) { $parent.width(shouldWidth); } if($parent.height() &lt; shouldHeight) { $parent.height(shouldHeight); } } } ); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload