setDragImage on Safari Crashes Unexpectedly

前端 未结 1 1455
暖寄归人
暖寄归人 2021-01-06 12:15

I am having difficulties determining why Safari 6.0+ crashes unexpectedly when trying to use the setDragImage() method.

I have a dragstart event and I would like to

相关标签:
1条回答
  • 2021-01-06 12:55

    I've determined that if the image element you are using on the setDragImage() method hasn't loaded, the browser will thread abort. The fix is simple. Make sure the image element is loaded before calling the method. The easiest way to do this is to create the image element outside of the event.

    //Preload the image
    var img = document.createElement("img");   
    img.src = "http://kryogenix.org/images/hackergotchi-simpler.png";
    
    dragMe.addEventListener('dragstart', function(e)
    {
        e.dataTransfer.setData('Test', 'some data');   
        e.dataTransfer.setDragImage(img, 0, 0);
    }, false);
    
    0 讨论(0)
提交回复
热议问题