Shashi Roy
Shashi Roy

Reputation: 333

Draggable image from Jquery is getting dragged to the whole page

I am using Jquery Draggable code from this link

I am trying to drag an image within a DIV but it is getting dragged to the whole page. My code is as follows

<div>
     <span class="move" id="draggable">
          <img src="cropped/image_name.jpg"/>
     </span>
</div>

I do not want this image to be draggable outside of the DIV. Rest of the code is working perfecrly. Please help me to solve this problem. Thanks in advance.

Upvotes: 0

Views: 87

Answers (3)

user2587132
user2587132

Reputation:

you don't want it to be visible outside the parent element???

overflow:hidden

Upvotes: 1

Working demo http://jsfiddle.net/cse_tushar/Lsc3r/1

 $("#draggable img ").draggable({ containment: "#div1" });

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388316

Try using the containment option

$('#draggable img').draggable({
    containment: $('#draggable').parent()
})

Upvotes: 3

Related Questions