I have this code, but it execute only once…
$('.' + container).hover(function() {
t = setTimeout( function(elem){
//this should be executed as long as I hover,
//with interval declared in viewSpped variable
$(elem).find('img').first().appendTo('.' + container).fadeOut(500);
$(elem).find('img').first().fadeIn(800);
}(this), viewSpeed);
}...
Any idea what I’m doing wrong? thanks!
setTimeout only call the callback once, that’s normal.
Maybe you want setInterval if you want your function to be executed at regular intervals.
And, incidently, there is another error in your code : You probably want
The arguments passed by
setIntervalorsetTimeoutto the callback are after the duration.Or, to be more compatible (note that the link I provide also gives the workaround for IE) :