Search code examples
javascriptjquerycssdraggable

Draggable Containment Option Doesn't Limit Item's Right or Bottom Borders?


I have a draggable item that I would like to contain within a div class. I have the following code

HTML:

<div class = 'right'>
<div id = 'frame1'>
      <iframe id = 'iframe1' src = 'http://www.wsj.com'></iframe>
    </div>
</div>
​

CSS:

.right {
        position: absolute;
        width: 60%;
        height: 100%;
        left: 25%;
        top: 20%;           
        background-color: #006400;
       }

#frame1 {
              position: absolute;
              float: left;
              width: 45%; 
              height: 75%; 
              top: 10%;
              left: 2%;
              margin: 10px; 
              border-style: solid; 
              border-width: 10px;
         }    
#frame2 {
              position: absolute;
              float: right;
              width: 45%; 
              height: 75%; 
              top: 10%;
              right: 2%;
              margin: 10px; 
              border-style: solid; 
              border-width: 10px;
        }
#frame3 {
            position: absolute;
            float: center;
            width: 45%;
            height: 75%;
            top: 10%;
            left: 25.5%;
            margin: 10px;
            border-style: solid;
            border-width: 10px;
        }
#iframe1 {
          width: 181%; 
          height: 182%; 
          top: 50%;
          left: 50%;
          zoom: 1.00; 
          -moz-transform: scale(0.55); 
          -moz-transform-orgin: 0 0;
          -o-transform: scale(0.55); 
          -o-transform-origin: 0 0; 
          -webkit-transform: scale(0.55); 
          -webkit-transform-origin: 0 0;
         }

JavaScript:

$("#frame1, #frame2, #frame3").draggable({containment: ".right", stack: "div"});​​

The draggable item is limited in its movement on the left and top borders of the div class, but there doesn't seem to be a limit as to how far out I can move the object to the right or bottom. What do I need to change in my code to get the draggable option contained on all four sides of the div class?

jsFiddle here


Solution

  • Yeah, Just update the following css for your iframe. i hope this will help you to get the draggable option contained on all four sides of the div class.

    #iframe1 {
              position: absolute;
              width: 181%; 
              height: 182%;
              zoom: 1.00; 
              -moz-transform: scale(0.55); 
              -moz-transform-orgin: 0 0;
              -o-transform: scale(0.55); 
              -o-transform-origin: 0 0; 
              -webkit-transform: scale(0.55); 
              -webkit-transform-origin: 0 0;
             }
    

    here i have updated the jsfiddle with the answer.