Created
April 3, 2013 14:49
-
-
Save andr3/5301866 to your computer and use it in GitHub Desktop.
Sometimes I have to explain this logic, this gist makes it easier. ;)
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
// Quick implementation of ResponsiveEnhance by Josh Emerson | |
// Original implementation: https://github.com/joshje/Responsive-Enhance | |
// <img src="sd.jpg" data-hd="hd.jpg"> | |
function quickUpgrade (obj) { | |
var tmp = new Image(); // prepare a loose image to make the request & cache it | |
var newsrc = obj.getAttribute('data-hd'); // grab the URL of hd version | |
if (newsrc) { // make sure it's there | |
tmp.onload = function () { // do this only when new img is loaded & cached | |
obj.src = newsrc; // switcheroo | |
}; | |
tmp.src = newsrc; // start the request (while leaving sd version visibile/in DOM) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment