Skip to content

Instantly share code, notes, and snippets.

@karlwestin
Created August 31, 2011 15:08
Show Gist options
  • Save karlwestin/1183781 to your computer and use it in GitHub Desktop.
Save karlwestin/1183781 to your computer and use it in GitHub Desktop.
Image changing, then changing back, then changing the next image
$(document).ready(changer);
function changer() {
var imgnum = Math.floor(15 * Math.random());
var time = Math.floor(5000 * Math.random());
var $img = $('.project_thumb .cardimgcrop img').eq(imgnum);
var newsrc = "http://yaplog.jp/cv/omb-master/img/449/noise_p.gif";
$img.css({
'width': $img.css('width'),
'height': $img.css('height')
});
$img.data("oldsrc", $img.attr("src"));
$img.attr("src", newsrc);
// creating timeout for changing image back
setTimeout(function() {
$img.attr("src", $img.data("oldsrc"));
// create timeout for calling the next "changer"
setTimeout(changer, time);
}, 1500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment