The function is executed after the user clicked on the link for 2 seconds

Yes, I know that this question was asked before, but I canโ€™t find an answer that works. This is an accepted answer from one of the other questions:

$('#element').hover(function()
{
    $(this).data('timeout', window.setTimeout(function()
    {
        alert('hovered for 2 seconds');
    }, 2000));
},
function()
{
    clearTimeout($(this).data('timeout'));
    alert('mouse left');
});

http://jsfiddle.net/nCcxt/

As you can see, he is not doing what he should.

I just need it in theory, but I canโ€™t get it to work - when the user clicked on the link for 2 seconds, the function is called. If the user moves the mouse away to the passage after 2 seconds, nothing happens.

+5
source share
1 answer

The code works great . It is interrupted only due to calls alert()that trigger the mouseout event.

? alert() focus/hover/mousemove.

, jQuery , : http://cherne.net/brian/resources/jquery.hoverIntent.html

+14

All Articles