Skip to content

Instantly share code, notes, and snippets.

@bcalloway
Created March 12, 2014 20:22
Show Gist options
  • Save bcalloway/9515492 to your computer and use it in GitHub Desktop.
Save bcalloway/9515492 to your computer and use it in GitHub Desktop.
HTML5 localstorage
<img id="slideImg_2" data-loc="http://c413794.r94.cf1.rackcdn.com/pages/02_intro.jpg" class="load_later" alt="Alta, UT" />
$('.load_later').each(function (index) {
var target = this;
var id = $(this).attr("id");
setTimeout(function () { late_image(target, id) }, 1000 + (130 * index));
});
function late_image(target, id) {
if ( localStorage.getItem(id)) {
imagesrc = localStorage.getItem(id);
}
else {
imagesrc = $(target).data("loc");
localStorage.setItem(id, imagesrc);
}
$(target).attr("src", imagesrc);
// var imagesrc = $(target).data("loc");
// $(target).attr("src", imagesrc);
//console.log('image');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment