2

我以为这很简单,但错了……尝试使用 .delay 和在线找到的其他方法的组合,但无法让它在没有错误的情况下工作。

当您将鼠标从 .hover-area 上移开时,我只想添加一秒钟的延迟...有什么想法吗?

提前致谢!!!

$('.forward').css({ opacity:0, right:-20 });
$('.backward').css({ opacity:0, left:-20 });

$('.hover-area').hover(function () {
  var conf_1 = { queue:false, duration:300, easing:'easeOutCubic' };
  var conf_2 = { queue:false, duration:400, easing:'easeOutCubic' };

  $(this).find('.backward, .forward').each(function () {
    $(this).stop()
      .animate($(this).data('animate-on'), conf_1)
      .animate({ opacity:0.7 }, conf_2);
  });
}, function() {
  var conf_1 = { queue:false, duration:550, easing:'easeOutSine' };
  var conf_2 = { queue:false, duration:300, easing:'easeOutSine' };

  $(this).find('.backward, .forward').each(function () {
    $(this).stop()
      .animate($(this).data('animate-off'), conf_1)
      .animate({ opacity:0 }, conf_2);
  });
}); 
4

2 回答 2

0

我认为您可以简单地使用setTimeout. 将整个代码包装在要执行的函数中mouseout,并将其与setTimeout.

看看这个样本或试试这个小提琴http://jsfiddle.net/mvcGN/

HTML

<div id="test">
</div>

CSS

#test{
    width:200px;
    height:200px;
    background-color:#000;
}

jQuery

jQuery(document).ready(function($){
    $('#test').hover(function(){
        $(this).css("background-color","#456765");
    },function(){

//wrap your code in a function like this
        function do_it_after_delay(){
        $('#test').css('background-color','#567324');
        }


//simply use setTimeout to execute is with a delay
    setTimeout(do_it_after_delay,5000);

    });
});

此代码将更改#test鼠标进入时的颜色,DIV并在鼠标离开 5 秒后再次更改颜色DIV

于 2013-03-05T12:26:09.820 回答
0

一切似乎都很好,只需.delay()尝试一下:.stop()your callback function

$(this).find('.backward, .forward').each(function () {
$(this).stop().delay(1000)
  .animate($(this).data('animate-off'), conf_1)
  .animate({ opacity:0 }, conf_2);
});

我在这里所做的只是.delay()在你的mouseout回调中添加了一个function()

于 2013-03-04T08:29:22.510 回答