Created
September 15, 2011 11:23
-
-
Save kopiro/1219036 to your computer and use it in GitHub Desktop.
Set thumb-image in Javascript
This file contains hidden or 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
setThumbImage = function(e, src) { | |
var img = new Image(); | |
img.src = src; | |
img.onload = function() { | |
console.log("img loaded"); | |
e.style.backgroundImage = 'url('+src+')'; | |
e.style.backgroundPosition = 'center'; | |
e.style.backgroundRepeat = 'no-repeat'; | |
e.style.backgroundSize = (img.width>img.height ? 'auto 100%' : '100% auto'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment