Proper way to reset a GIF animation with display:none on Chrome

后端 未结 11 1518
暗喜
暗喜 2020-12-03 05:21

Title is self-explanatory, but I\'ll provide a step-by-step view on the matter. Hopefully I\'m not the first one to have noticed this (apparently) bug on Webkit/Chrome.

11条回答
  •  醉梦人生
    2020-12-03 05:48

    I experienced problems with all of the above solutions. What finally worked was replacing the src temporarily with a transparent 1px gif:

    var transparent1PxGif = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
    var reloadGif = function(img) {
        var src = img.src;
        img.src = transparent1PxGif;
        img.offsetHeight; // triggers browser redraw
        img.src = src;
    };
    

提交回复
热议问题