2013-10-16 203 views
0

我想修改我的範圍內的文本後,CSS將完成我的動畫(200毫秒)。我想通過一個delay參數到我的懸停狀態,所以它會等待。我的代碼如下:jQuery - 延遲懸停

$('.overlay').each(function() { 
    var text = $(this).children('.category').children('span').text(), 
     newtext = text.substring(0,1); 

    $(this).children('.category').children('span').text(newtext); 

    $(this).delay(5000).hover(function() { 
     $(this).children('.category').children('span').delay(5000).stop().text(text); 
    }, function() { 
     $(this).children('.category').children('span').text(newtext); 
    }) 
}); 

不幸的是,這是行不通的,無論在哪裏,我把delay。我能做什麼?

回答

1

我不確定你可以使用延遲來處理那些不具有這種語法效果的東西,那麼爲什麼不使用Javascript的setTimeout呢?它似乎會更簡單。

$(this).hover(function() { 
    var that = this; 
    setTimeout(function(){ 
    $(that).children('.category').children('span').text(newtext); 
    },5000); 
})