anosim
anosim

Reputation: 73

image draggable not working in parent containment

This example working great because here containment is body http://jsfiddle.net/roXon/hMmbK/2/

when i use container in html, it work not fine. here the problem: http://jsfiddle.net/anosim/ZXu2w/

anyone have best solution for that.

Thanks in Advance.

Upvotes: 1

Views: 2816

Answers (2)

RestingRobot
RestingRobot

Reputation: 2978

Your problem is that you're making the img tag draggable in the second fiddle. I'm assuming you want the user to be able to drag the image around the green area. Try applying draggable to the div instead. (fiddle: http://jsfiddle.net/ZXu2w/1/ )

Upvotes: 0

Jeff B
Jeff B

Reputation: 30099

The problem is that when you specify coordinates, they are absolute positions.

There might be a better way, but you can always get the offset of the parent and add those offsets to your containment coordinates:

$(function() {

    var ox = $("#container img").parent().offset().left;
    var oy = $("#container img").parent().offset().top;

    $("img").draggable({
        containment: [-99+ox, -119+oy, ox, oy],
        scroll: false
    });

});

Demo: http://jsfiddle.net/DqdRK/

Upvotes: 2

Related Questions