English 中文(简体)
如何在鼠标退出时添加延迟
原标题:How to add delay on mouse-out

我试图实施其他解决方案,但毫无运气... 希望有人能帮助解决我徘徊的延迟问题...我只需要在鼠标退出时加上一个短暂的延迟。

提前感谢!

            $( .forward ).css({opacity:0, right:0});
            $( .hover-area ).hover(function() {
                $(this).find( .forward ).stop()
                    .animate({right:20}, {queue:false, duration:300, easing: easeOutCubic })
                    .animate({opacity: 0.95 }, {queue:false, duration:400, easing: easeOutCubic });
            },function() {
                $(this).find( .forward ).stop()
                    .animate({right:0}, {queue:false, duration:550, easing: easeOutSine })
                    .animate({opacity: 0 }, {queue:false, duration:300, easing: easeOutSine });
            });
最佳回答

您可以使用 setTimeout () 延迟 mouseout

$( .forward ).css({opacity:0, right:0});

    function toogler(element, showHide) {
        if (showHide ==  show ) {
            $(element).find( .forward ).stop().animate({
                right: 20
            }, {
                queue: false,
                duration: 300,
                easing:  easeOutCubic 
            }).animate({
                opacity:  0.95 
            }, {
                queue: false,
                duration: 400,
                easing:  easeOutCubic 
            });
        } else {
            setTimeout(function() {
                $(element).find( .forward ).stop().animate({
                    right: 0
                }, {
                    queue: false,
                    duration: 550,
                    easing:  easeOutSine 
                }).animate({
                    opacity: 0
                }, {
                    queue: false,
                    duration: 300,
                    easing:  easeOutSine 
                });
            }, 1000);
        }
    }

    $( .hover-area ).hover(function() {
        toogler(this,  show );
    }, function() {
        toogler(this,  hide );
    });​

http://jsfidd.net/p4enD/10/" rel = "notfollow" >DEMO

问题回答

您需要调用< a href=> “ https:// developmenter.mozilla. org/ en/ DOM/ window. setTimeout" rel=“ nofollow” >setTimeout 函数, 该函数在特定时间段后会调用函数。 跟踪动画代码的调用按时间顺序排列的位置也是可取的, 这样您就不会运行动画片 。

var MOUSEOUT_ANIM_THRESHOLD = 5000;
var mouseInTime = {};

function onMouseOut( object, serial ) {
   if( serial < onMouseOut.serial ) {
       return;
   }

   $(object).find( .forward ).stop()
       .animate({right:0}, {queue:false, duration:550, easing: easeOutSine })
       .animate({opacity: 0 }, {queue:false, duration:300, easing: easeOutSine });
}

onMouseOut.serial = 0;

$( .forward ).css({opacity:0, right:0});
$( .hover-area ).hover(function() {
    $(this).find( .forward ).stop()
        .animate({right:20}, {queue:false, duration:300, easing: easeOutCubic })
        .animate({opacity: 0.95 }, {queue:false, duration:400, easing: easeOutCubic });

    mouseInTime[this] = new Date().getTime();
},function() {
    var deltaTime = new Date().getTime() - mouseInTime[this];

    if( deltaTime < MOUSEOUT_ANIM_THRESHOLD ) {
         setTimeout(onMouseOut, 250, this, onMouseOut.serial++); //250ms delay
    } else {
          $(object).find( .forward ).stop()
              .animate({right:0}, {queue:false, duration:0})
              .animate({opacity: 0 }, {queue:false, duration:0});
    }
});




相关问题
images sliding continuously with <table> and jQuery

I m trying to write a little test page that circulates images through a window (see image). I have colored boxes inside a table (gray border), with each box being a element. <table id="boxes" ...

WPF 3d rotation animations

I have a few 3d rectangles on my screen that I want to pivot around the Y axis. I want to press down with the mouse, and rotate the 3d object to a max rotation, but when the user moves their mouse, ...

Disable Windows 7 touch animation in WPF

In Windows 7 when you touch the screen there is a short animation that occurs at the touch point. In my WPF app I want to display my own touch points, without showing the one supplied by Windows. ...

jQuery block moving

I wanna move a div block to the top, so I coded like this: CSS part: .movingPart{ margin-top:80px; } jQuery part: $(document).ready(function() { $( #btn ).click(function() { $( .movingPart )....

Direct 2D gnuplot PNG animation?

Can anyone please confirm that yes/no Gnuplot 4.5 (on CVS) can output 2D animated PNG files? I have numerous datasets but one line that I d like to show iteratively in 3 different places in my graph. ...

Visual State Manager VS Animations in WPF

There is a lot of talk about the simplicity of Visual States and the transitions between them in WPF/Silverlight. I have the need to generate animations dynamically at runtime, to animate the ...

Create a ImageIcon that is the mirror of another one

I ll like to know if there is a way to create a ImageIcon that is the mirror of another ImageIcon. Searching on Google, I found how to do it by using many AWT libraries. Is there a way to do it with ...

how to drag in the animation in iphone application?

Iphone application is using the static co-ordinates to reach at some points in the application,which is based on the button event. But what i want is when i drag the item than it should reach at some ...

热门标签