2

これは簡単だと思いましたが、間違っていました... .delay とオンラインで見つかった他の方法の組み合わせを使用してみましたが、バグなしでは動作しませんでした。

.hover-area からマウスを離したときに 1 秒の遅延を追加したいだけです... 何かアイデアはありますか??

前もって感謝します!!!

$('.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()を追加しただけです。mouseoutfunction()

于 2013-03-04T08:29:22.510 に答える