Why doesn't HTML5 drag and drop work in Firefox?

前端 未结 5 1325
感动是毒
感动是毒 2021-02-01 02:36

I have bound events to different elements, and when I drag them in all browsers, except Firefox, it works as expected. In firefox, however, it doesn\'t work at all. The only eve

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 02:50

    Firefox requires that a user run the dataTransfer.setData function in the event.

    For you jQuery users, that means the following code should resolve your issue:

    function dragstartHandler(event){
    
      event.originalEvent.dataTransfer.setData('text/plain', 'anything');
    
    }
    

    Future events on the same drag will now properly fire as you expected. Obviously you can replace the setData arguments with more useful data.

提交回复
热议问题