JQuery .hover()can use a function for states mouseoverand mouseout, therefore, it is trivial to do something like
HTML:
<img id="swap" src="http://lorempixum.com/200/200/sports" alt=""/>
JQuery
var images = ["http://lorempixum.com/200/200/sports",
"http://lorempixum.com/200/200/food",
"http://lorempixum.com/200/200/abstract",
"http://lorempixum.com/200/200/people",
"http://lorempixum.com/200/200/technics",
"http://lorempixum.com/200/200/city"
],
i = 0,
$swap = $("#swap"),
swapper;
function swapImg(){
i = i % images.length;
$swap.attr("src",images[i]);
i++;
}
$swap.hover(function(){
swapper = setInterval(swapImg,10);
},function(){
clearInterval(swapper);
});
here is a demo
I use http://lorempixel.com/ for dummy images, but every time you request it, they return a random image, so this displays more images than in the array, and this sometimes makes funky overlays work.
source
share