Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#8830 closed bug (duplicate)

Event hover() when fast pointing to an element

Reported by: monolithed@… Owned by:
Priority: high Milestone: 1.next
Component: effects Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:

Description

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
    $('div').hover(function() {
        $('p').animate({
            height: 'toggle',
            opacity: "toggle"
        }, {
            queue: false,
            duration: 500
        });
    });
});
</script>
<style type="text/css">
p {
    background: red;
    width: 100px;
    height: 100px;
}
</style>

<div>text</div>
<p style="display: none;"></p>


And this bug (can't stop event when fast pointing to an element):

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
    $('div').hover(function(event) {
        $('p')[event.type == 'mouseenter' ? 'show' : 'hide'](100);
    });
});
</script>
<style type="text/css">
p {
    background: red;
    width: 100px;
    height: 100px;
}
</style>

<div>text</div>
<p style="display: none;"></p>

please see it here: http://jsfiddle.net/uw8yU/2/ and http://jsfiddle.net/uw8yU/1/

Change History (4)

comment:1 Changed 8 years ago by timmywil

Component: unfiledeffects
Priority: undecidedhigh
Resolution: duplicate
Status: newclosed

This may not be ideal, but you can use .stop to withhold the toggle values if you hover again before completion. http://jsfiddle.net/timmywil/uw8yU/3/ jQuery does not save state for animations, but we're looking into changing that. See duplicate ticket.

comment:2 Changed 8 years ago by timmywil

Duplicate of #8685.

comment:3 Changed 8 years ago by timmywil

I may have misread your ticket and leaped too quickly to relate it to #8685. You do need to handle debouncing your hovers.

The hover events (mouseenter and mouseleave) are fired whenever the user hovers the element, however quickly. You probably need to make sure the user wants to hover. hoverIntent (http://bit.ly/QJz5) and $.event.special.hover (http://bit.ly/1VBJW) will automatically normalize the hover event, or you can debounce manually using throttle/debounce (http://bit.ly/e8d9TB). Animating? How .stop() works (http://bit.ly/5kq9xo)

Last edited 8 years ago by timmywil (previous) (diff)

comment:4 in reply to:  3 Changed 8 years ago by monolithed@…

timmywil, thx for your reply. I did't know about this way with stop(1,1).animate(). And I think you'd add the one to docs in examples.

But why this http://jsfiddle.net/uw8yU/4/ way with stop() doesn't work?

Note: See TracTickets for help on using tickets.