我有這樣的代碼,但只執行一次的工作...的setTimeout代碼不使用jQuery
$('.' + 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);
}...
任何想法,我做錯了嗎?謝謝!
您正在執行該函數,而不是將它傳遞給setTimeout。在函數聲明之後放下'(this)'。 –
看到一個簡單的功能可以被扭曲和破壞,然後「譴責」別的東西的不同方式總是有趣的。 –