【问题标题】:Get the type of the element which is dragged at the moment获取当前被拖动元素的类型
【发布时间】:2016-04-08 13:58:54
【问题描述】:

在我的网站中有一个 div,如果您将某些内容拖入浏览器,则会显示该 div,如果您将其放下,则该 div 会消失。

function startDraghandler() {
  $("*").on("dragover", function(event) {
    $("*").off("dragover");
    $("#uploadbox").animate({bottom:"+=360px"}, 250);
    $("*").on("mouseover", function() {
      $("#uploadbox").animate({bottom:"-=360px"}, 250);
      $("*").off("mouseover");
      startDraghandler();
    })
  });
}

但是,如果您从网站本身拖动某些内容,我不希望 div 显示,只有当它来自浏览器外部时才显示。如果您从站点中拖动一个元素,我希望发生一些不同的事情。但是我不知道怎么做,因为我在网上找到的都是如何在拖放时获取拖动元素的类型。

感谢您的帮助

【问题讨论】:

    标签: javascript jquery html drag-and-drop


    【解决方案1】:

    There is not possible 了解 dragEvents 中的数据,dragStartdragEnd 事件除外。

    但可能存在一种解决方法,测试一下并告诉我它是否适合您:

    // Variable declaration
    var insidePage = false;
    
    // When any element on document is dragged, set the var in true value.
    $(document).on("dragstart", function(evt) {
        insidePage = true;
    });
    
    $(document).on("dragend", function(evt) {
        insidePage = false;
    });
    
    // Only executes the function if the element that is dragged is coming from outside the document
    $(document).on("dragover", function(evt) {
      if(!insidePage){  
        // Code to drag from outside
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 2010-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      相关资源
      最近更新 更多