Safari 5.1 broke HTML native drag and drop?

前端 未结 4 425
傲寒
傲寒 2021-02-02 13:49

Last night, I thought I\'d do a quick project to demonstrate HTML5 capabilities and to try some things out. However, I can\'t seem to figure out how to get drag and drop to work

4条回答
  •  爱一瞬间的悲伤
    2021-02-02 14:23

    I encountered similar issues, the drop event appeared to not be firing. Safari apparently expects the "dragover" event to also be bound. As soon as I also added that, it worked. So ... I'm sharing in case it's relevant.

    My first attempt:

    $(document).bind 
      drop: (e) ->
        // This never gets fired in safari (does work in chrome)
        console.log e.originalEvent.dataTransfer.files
        false
    

    My "fix":

    $(document).bind 
      dragover: (e) ->
        console.log e
        false
      drop: (e) ->
        // This does get fired (in chrome and safari)
        console.log e.originalEvent.dataTransfer.files
        false
    

提交回复
热议问题