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

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();

Leave a Comment