Drop event not firing in chrome

后端 未结 4 1643
生来不讨喜
生来不讨喜 2020-12-02 18:02

It seems the drop event is not triggering when I would expect.

I assume that the drop event fires when an element that is being dragged is releases above the target

4条回答
  •  孤街浪徒
    2020-12-02 18:20

    In order to have the drop event occur on a div element, you must cancel the ondragenter and ondragover events. Using jquery and your code provided...

    $('.drop').on('drop dragdrop',function(){
        alert('dropped');
    });
    $('.drop').on('dragenter',function(event){
        event.preventDefault();
        $(this).html('drop now').css('background','blue');
    })
    $('.drop').on('dragleave',function(){
        $(this).html('drop here').css('background','red');
    })
    $('.drop').on('dragover',function(event){
        event.preventDefault();
    })
    

    For more information, check out the MDN page.

提交回复
热议问题