Reputation: 143
I am trying to create a draggable div with an image. I could drag a div with some text, but whenever I replace the text with an image dragging not working fine. Please check this link, If you replace the image with text, it will be able to drag the text on the window,but it wont work if we replace the text with an image as it is now
Please help
Thank you for the consideration
Upvotes: 1
Views: 102
Reputation: 244
Another fast fix is just not using the img tag but css to set the background-image of the div and its width , height. This will also work.
Upvotes: 0
Reputation: 35657
I just tested it myself, you need to do:
$('#dv').mousedown(function(e){
e.preventDefault ();
x1 = e.pageX - parseInt($('#dv').css('left'));
y1 = e.pageY - parseInt($('#dv').css('top'));
drag = true;
})
This will prevent the browser drag-and-drop function.
HTH.
Upvotes: 1
Reputation: 11548
you need to use e.preventDefault() and pass e as a parmeter in the images mousemove function
Upvotes: 0