jQuery - 延迟悬停

时间:2013-10-16 12:10:17

标签: javascript jquery

我希望在css完成我的动画(200ms)之后对我的跨度内的文本进行修改。我想将delay参数传递给我的悬停状态,所以它会等待。我的代码如下:

$('.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 个答案:

答案 0 :(得分:1)

我不确定你是否可以使用延迟来处理那种语法没有效果的东西,那么为什么不使用Javascript的setTimeout呢?看起来它会更简单。

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