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

后端 未结 11 1523
暗喜
暗喜 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

    The most reliable way to "reset" a GIF is by appending a random query string. However this does mean that the GIF will be redownloaded every time so make sure it's a small file.

    // reset a gif:
    img.src = img.src.replace(/\?.*$/,"")+"?x="+Math.random();
    

提交回复
热议问题