如何在按住鼠标左键的情况下获取鼠标位置以在web中选择和拖动文本

how to get the mouse position while the left button is down to select and drag text in web

本文关键字:鼠标 web 选择 文本 拖动 位置 情况下 获取      更新时间:2023-09-26

目前,我想做的效果是:选择文本,然后通过js或jquery将其拖放到网页中的某个框中,但当我选择文本并拖动时,维度值无法动态更新,所以我的问题是:当鼠标左键按下以选择和拖动文本时,如何动态获取鼠标位置?非常感谢。

http://jsfiddle.net/SEZzq/1/

http://jsfiddle.net/SEZzq/4/

http://jsfiddle.net/SEZzq/5/

$(window).mousedown(function(e) {
    if (e.which == 1) {
        $(window).bind('mousemove', function(e) {
            $('div').text('clientX: ' + e.clientX + ' clientY: ' + e.clientY);
        });
    }
}).mouseup(function(){
    $(window).unbind('mousemove');
});