开发者

issue when dragging an image using javascript (jQuery)

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


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜