Created
March 24, 2017 19:23
-
-
Save srstanic/32a0ad72cac4e1e07138f4a82b239ccf to your computer and use it in GitHub Desktop.
Load gif in background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gifs = { | |
'imageElementId': 'http://example.com/myimage.gif' | |
} | |
function getUpdateImageSrcFunc(imageId) { | |
return function() { | |
document.getElementById(imageId).src = this.src; | |
} | |
} | |
for (var imageId in gifs) { | |
var gifSrc = gifs[imageId] | |
var gifImage = new Image(); | |
gifImage.onload = getUpdateImageSrcFunc(imageId) | |
gifImage.src = gifSrc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment