Android Native Browser duplicating HTML5 canvas (fine in chrome)

后端 未结 4 1569
难免孤独
难免孤独 2020-12-31 09:47

This is a weird issue that I am only experiencing on a Native browser on Samsung Galaxy Tab 2 and Galaxy S2 in the native browser.

This has also been tested on othe

4条回答
  •  一向
    一向 (楼主)
    2020-12-31 10:17

    I ran into this same issue. I was able to fix this by running the following code after making a change to my canvas:

    // If Samsung android browser is detected
    if (window.navigator && window.navigator.userAgent.indexOf('534.30') > 0) {
    
        // Tweak the canvas opacity, causing it to redraw
        $('canvas').css('opacity', '0.99');
    
        // Set the canvas opacity back to normal after 5ms
        setTimeout(function() {
            $('canvas').css('opacity', '1');
        }, 5);
    
    }
    

    By tweaking the opacity, this forced the canvas to redraw and removed the duplicate shapes. It's a dumb fix but it works. Hopefully this helps someone.

提交回复
热议问题