


The jquery events hover, mouseenter, and mouseleave only trigger animation once
jquery hover mouseenter mouseleave event is only triggered once animation
jquery.mouseenter(function(){ $(div).animate({'margin-top':'100px'},1000) }) jquery.mouseleave(function(){ $(div).animate({'margin-top':'200px'},1000) })
Move the mouse to a certain div, trigger the mouseenter event and animation, move out and trigger the mouseleave event and animation, but when the div is moved back and forth, the event is triggered multiple times, and the animation is repeated several times. How can the mouseenter and mouseleave events not be triggered during the execution of the animation? That is, during the animation process, the mouse moves over the div. After that, the animation will not reappear. It will only be triggered after the animation is finished and it is crossed again.
You can use the stop method:
$(div).stop(false, true).animate({'margin-top':'100px'},1000);
If the first parameter of stop() is true, Indicates that the current animation queue will be cleared immediately, the default is fx; if the second parameter is true, it means that the currently executing animation will be immediately set to its end state.
Judgment before executing animation:
if (!$(obj).is(':animated')) { // to do something }
If the selected Element is not in the animation state, the animation will be executed. Otherwise, ignore it
^_^ (the expression of encountering a question that has been clearly answered before)
This is called the "animation atomicity problem" by @Humphry. That is to say, if the animation action is a non-reentrant atomic process, then how to implement this feature in the code.
A very clear answer can be found here. The answer is the obvious marking method: align the element to be animated, set the mark when the animation starts, and remove it when it ends (using callback function). When there is a logo, the event that starts the animation must not be triggered.
The above is the detailed content of The jquery events hover, mouseenter, and mouseleave only trigger animation once. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of jQuery reference methods: Quick start guide

How to use PUT request method in jQuery?

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page

Use jQuery to modify the text content of all a tags

In-depth analysis: jQuery's advantages and disadvantages

Understand the role and application scenarios of eq in jQuery

How to tell if a jQuery element has a specific attribute?
