0

In my site there is a div which shows up if you drag something into the browser and disappears if you dropped it.

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

But I don't want the div to show up if you dragged something from the site itself, only when it's coming from outside the browser. If you drag an element from the site, I want something different to happen. But I don't know how to do this, because all I've found on the internet is how to get the type of the dragged element when it's dropped.

Thanks for your help

thanksd
  • 54,176
  • 22
  • 157
  • 150

1 Answers1

0

There is not possible to know the data in the dragEvents except in the dragStart and dragEnd events.

But could exist a workaround, test this and tell me if it works ok for you:

// 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
  }
});
Community
  • 1
  • 1
ElChiniNet
  • 2,778
  • 2
  • 19
  • 27