Triggering a draggable on mousedown
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"/>
</d开发者_高级运维iv>
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??
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;
};
精彩评论