Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to restrict the draggable div in this case
    primarykey
    data
    text
    <p>I have the following html structure:</p> <p>HTML</p> <pre><code>&lt;div id="outer"&gt; &lt;div id="inner"&gt; &lt;div id="bounds"&gt; &lt;div id="myimage"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>CSS</p> <pre><code>#outer { border: solid 1px red; padding: 50px 30px 50px 30px; float: left; } #inner { width: 300px; height: 300px; border: solid 1px black; overflow:hidden; position:relative; } #myimage { background-image:url('http://upload.wikimedia.org/wikipedia/commons/9/9a/Sample_Floorplan.jpg'); background-position : 0,0; background-repeat:no-repeat; width: 648px; /*TODO : size will be dynamic*/ height: 438px; /*TODO : size will be dynamic*/ position:relative; } </code></pre> <p>JS</p> <pre><code>$("#myimage").draggable(); //{ containment: "#bounds" } //$("#bounds").width(); //? value //$("#bounds").height(); //? value //$("#bounds").css("left",""); //? value //$("#bounds").height("top","");? value </code></pre> <p><a href="http://jsbin.com/atavub/4/edit" rel="nofollow">Demo with JSBin</a></p> <p>A "inner" div which has a draggable child div with <code>background-image</code>.<br> The inner div has <code>overflow:hidden</code>. What i need is to restrict the drag of the image so that the whole image can be scrolled but the image should never be dragged completely out of the "inner" div (some part of the image must always remain visible). </p> <p>Thats why i added a <code>bounds</code> div . How can i define the dimensions and position for the <code>bounds</code> div which enables me to restrict the movement of the image.</p> <p>Such that i can write</p> <pre><code>$("#myimage").draggable({ containment: "#bounds" }); </code></pre> <p><a href="http://api.jqueryui.com/draggable/#option-containment" rel="nofollow">http://api.jqueryui.com/draggable/#option-containment</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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