views:

35

answers:

3

Hi all,

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

A: 

you need to use e.preventDefault() and pass e as a parmeter in the images mousemove function

XGreen
e is already a parameter to the mousemove function?
roe
Thank you XGreen,
milan
glad it helped.
XGreen
+1  A: 

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.

roe
Thank you roe, you done it. Thank you very much :) :)
milan
But it doesn't work in ie6 with your code, working in firefox, chrome. do you have any suggestions ?
milan
@milan; I'm sorry, IE6 was released nine years ago, there's a lot of stuff not working there. Unfortunately, I don't have an IE6 to even see what's happening, let alone figure out how to make it work, so I can't help you there. Sorry.
roe
A: 

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.

budinov.com
Thank you budinov.com your suggestion is also fine
milan