views:

264

answers:

1

Hi guys,

This is my problem i'm trying to create a event to trigger a draggable. Here is what i already tried.

<div id="ecard-canvas">
    <div id="ecard-border"></div>
    <img id="ecard-image" src="images/content/girl.jpg" alt="chick"/>
</div>

and the JS.

$('#ecard-image').draggable();

$('#ecard-border').mousedown( function(event){
    $('#ecard-image').trigger("mousedown.draggable", [event]);
});

But offcourse this doesn't work the mousedown event fires but the mousedown.draggable isn't triggerd. is this even possible? What am i doing wrong??

A: 

Well i solved it after some more thinking here is my code.

html

<div id="ecard-canvas">
    <div id="ecard-image-handle"></div> //absolute z-index:30 
    <div id="ecard-border"></div> //absolute z-index: 20 and has a nice background border set to it
    <img id="ecard-image" src="yourimage" />  //relative z-index: 10
</div>

javascript

//get objects   
    oImage.obj = $('#ecard-image');
    oImage.handle = $('#ecard-image-handle')

// set drag handler
oImage.handle.draggable({
        addClasses: false,
        drag: imageConstrain
    });


//ondrag function
function imageConstrain(oEvent, oUI){
    var newPosition = oUI.position;

    oImage.obj.css({ 'left': newPosition.left, 'top': newPosition.top  });
    return newPosition; 
};
Wieringen