Skip to content

Instantly share code, notes, and snippets.

@Takazudo
Created February 3, 2011 08:30
Show Gist options
  • Save Takazudo/809205 to your computer and use it in GitHub Desktop.
Save Takazudo/809205 to your computer and use it in GitHub Desktop.
do preload using custom data attr.
<img
src="hogehoge_on.png"
data-srcoff="hogehoge_off.png"
data-preloadattr="srcoff"
alt=""
/>
$(function(){
$('img[data-preloadattr]').each(function(){
var $el = $(this);
var attr = $el.data('preloadattr');
(new Image).src = $el.data(attr);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment