Created
August 31, 2011 15:08
-
-
Save karlwestin/1183781 to your computer and use it in GitHub Desktop.
Image changing, then changing back, then changing the next image
This file contains 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
$(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