Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Get mouse position while dragging link

I'm trying to track the mouse position while I click and drag an a[href] value to the bookmarks bar (it's for a bookmarklet). It seems to stop tracking a few seconds after I start dragging.

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/

like image 979
Adam Storr Avatar asked May 29 '12 18:05

Adam Storr


1 Answers

You need to return false in your mousedown handler, to prevent the default action of selecting text upon drag.

Updated fiddle

like image 61
lanzz Avatar answered Oct 16 '22 13:10

lanzz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!