0
votes

Im trying to figure this out like desperate but I couldn't come up with the right way.

Im trying to offer users the ability to change the background picture by drag-and-drop a picture into the browser. However, I can't be able to detect the drag events properly. when using

$(window).on 'dragenter', (e) =>
  console.log e.target
$(window).on 'dragleave', (e) =>
  console.log e.target

I always get the events triggered on individual DOM elements but never on the window/body itself, meaning if my DOM elements/container/wrapper dont cover the whole window, it does not work properly. I know it's possible since GMail can make it work somehow, but I seriously don't know what I'm doing wrong here.

Thanks!

1

1 Answers

0
votes

If I'm interpreting your question correctly, you need to bind the events to $(document). Because of event propagation, everything should eventually bubble up to document. If you only want the dragging to work for a specific part of the page, try using classes/class selectors.