Blog - SilverDiamond's site

Firefox drag and drop bug

While doing stuff related to https://gitlab.com/silvercraft/slibindex ’s webui firefox wouldn’t render large enough pngs in the ghost that appears when you start dragging an element the first time you drag it.
So the workout I found was drawing the image at least once in js.

element.addEventListener('dragstart', (e) => {
    /* Firefox bug for drag thingy not including image the first time*/
    if (navigator.userAgent.toLowerCase().includes('firefox')) {
        const img = card.querySelector('img.art');
        if (img && img.complete) {
            const canvas = document.createElement('canvas');
            canvas.width = 1; canvas.height = 1;
            const ctx = canvas.getContext('2d');
            ctx.drawImage(img, 0, 0, 1, 1);
            /* for it to show up the first drag, it must be drawn already, gecko dumb so JUST fetching it doesn't work*/
        }
    }
});


Back to home