JQuery - Get mouse position when dragging a link

I try to track the position of the mouse while I click and drag the value of a[href] to the bookmarks bar (this is for the bookmarklet). It seems to stop tracking after a few seconds after the start of the drag.

The code is below.

 var isDragging = false; $('a#dragthis') .mousedown(function() { $(window).mousemove(function(e) { isDragging = true; var x = e.pageX; var y = e.pageY; console.log(x + "|" + y); }); }); 

Here is a jsFiddle example: http://jsfiddle.net/GZpHP/

+7
source share
2 answers

You need to return false in your mousedown handler to prevent the default action when selecting text when dragging.

Updated fiddle

+2
source

I need the same thing, and in the end I used ondragstart and ondrop to register, and then processed the mouse position on the drop event.

This is not perfect, but he does the job.

0
source

All Articles