【问题标题】:Triggering Mousemove during Drag (HTML5)在拖动期间触发 Mousemove (HTML5)
【发布时间】:2014-01-06 11:45:16
【问题描述】:

有没有办法在dragenter事件触发后触发mousemove事件?

我要做的是根据元素的哪一侧(左侧或右侧)根据鼠标在元素上的位置输入新文本来更改视觉标记。

我已经为 mousemove 事件中的行为编写了代码,我还需要在拖动事件期间以某种方式触发它。

这是我的 mousemove 事件,它根据鼠标在元素内的位置在悬停元素之前或之后添加标记。

on('mousemove', function(e) {
    e.stopPropagation();
    var rect = $(this).get(0).getBoundingClientRect();
    var mousePosPercent_X = ((event.clientX-rect.left)/(rect.right-rect.left))*100;
    var mousePosPercent_Y = ((event.clientY-rect.top) /(rect.bottom-rect.top))*100;
    if(mousePosPercent_X < 50)
    {
        if($(this).prev().is('.insertpos'))
        {
        }
        else
        {
            $(".droptest").find(".insertpos").remove();
            $(this).before("<li class='insertpos leftpos'></li>");
        }
    }
    else
    {
        if($(this).next().is('.insertpos'))
        {

        }
        else
        {
             $(".droptest").find(".insertpos").remove();
             $(this).after("<li class='insertpos leftpos'></li>");
        }
    }
});

这是一个小提琴 http://jsfiddle.net/5K84p/1/

我必须使用原生 HTML5 拖放功能,我的唯一目的是即使在拖动事件正在进行时也能检测到鼠标移动。

非常感谢。

【问题讨论】:

    标签: javascript jquery html drag-and-drop


    【解决方案1】:

    Dragmove 事件成功了.. 不敢相信我在偶然发现它之前浪费了几个小时!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-14
      相关资源
      最近更新 更多