Home Web Front-end JS Tutorial The use of stop() in jquery

The use of stop() in jquery

Jun 30, 2017 am 11:30 AM
jquery stop

Purpose: In order to understand the usage of stop(), let’s take an example and see it in an intuitive way.

Physical object: A p with id="animater" contains a piece of text. (animator is used below to represent the actual object)

The final complete effect of the animation: animater moves to the right 800px (this complete process is animation 1), then, the font gradually becomes larger (this complete process is animation 2), then, the transparency gradually decreases to 0 (this complete process is animation 3), and then the transparency gradually returns to 1 (This complete process is animation 4), and then the font size becomes 16px and moves to a position 200px from the left border (this complete process is animation 5).

#Operation: Click on the buttons with different IDs to watch the effect.

##HTML code:

##

       <p id="animater">
            stop()方法测试        </p>
Copy after login
        <p id="button">
            <input type="button" id="button1" value="stop()"/>
            <input type="button" id="button2" value="stop(true)"/>
            <input type="button" id="button3" value="stop(false,true)"/>
            <input type="button" id="button4" value="stop(true,true)"/>
            
        </p>
Copy after login

CSS code:

         #animater{
                width: 150px;
                background:activeborder;
                border: 1px solid black;                /*为了移动,需设置此属性*/
                position: relative;
            }
Copy after login

jquery code:

              //            为了看效果,随意写的动画
                $('#animater').animate({                    'right':-800
                }, 3000).animate({'font-size':'16px'},'normal').animate({'font-size':'26px'},'normal').animate({'font-size':'36px'},'normal').animate({'font-size':'46px'},'normal').animate({'font-size':'56px'},'normal').animate({'opacity':0},'normal').animate({'opacity':1},'normal').animate({'left':200,'font-size':'16px'},'normal');        
                //           点击不同的button执行不同的操作        
                $('#button1').click(function(){                    //默认参数是false,不管写一个false还是两个false还是没写false效果一样
                    $('#animater').stop();
                });
                $('#button2').click(function(){                    //第二个参数默认false
                    $('#animater').stop(true);
                });
                $('#button3').click(function(){
                    $('#animater').stop(false,true);
                });
                $('#button4').click(function(){
                    $('#animater').stop(true,true);
                });
Copy after login

W3School has this description of: stop(

stopAll

,goToEnd)

##ParametersDescriptionstopAllgoToEnd Optional. Specifies whether the current animation is allowed to complete.

My understanding:

#When stopAll is false, all animations of the selected elements added to the queue will not be stopped, only the current one will be stopped. animation. When stopAll is true, stop all animations added to the queue (if goToend is true, jump directly to the final effect of the current animation).

When goToend is false, it is not allowed to jump directly to the final effect of the current animation ( should be the so-called completion of the current animation Animation bar), when goToend is true, it is allowed to jump directly to the final end effect of completing the current animation

Every time you run the page and the animater moves, click on different buttons and you will see the following different effects (click when the animator is in animation 1):

Click button button1 (stop()), due to two The parameters are all false. So when the click occurs, the animator does not jump to the final effect of the current animation (animation 1), but directly enters animation 2, and then animations 3, 4, and 5 until the entire animation is completed.

Click button button1 (stop(true)). Since the first one is true and the second one is false, the animator stops immediately and the animation stops moving.

Click button button1 (stop(false,true)). Since the first one is false and the second one is true, when the click occurs, the current animation (animation 1) of the animater stops and the animater directly Jump to the final end effect position of the current animation (Animation 1), and then execute the following animations (Animation 2, 3, 4, 5) normally until the entire animation is completed.

Click button button1 (stop(true, true)). Since both are true, when the click occurs, the animater jumps to the final end effect position of the current animation (animation 1), and then all animations stop. .

Actual cases encountered at work:

I made a drop-down menu in the project, when the mouse moves up When the menu is displayed, the menu is hidden when the mouse leaves.

If I move the mouse in and out of the menu quickly and continuously (that is, when the menu drop-down animation is not completed, the mouse moves out of the menu again). "Animation accumulation" will occur. When the mouse stops moving, the accumulated animation will continue to be executed until the animation sequence is completed.

Solution: Add stop(true,true# before writing the animation effect code ##), so that every time you quickly move in and out of the menu, it will be normal. When moving into a menu, stop all animations added to the queue, but complete the current animation (jump to the final effect position of the current animation)

Optional. Specifies whether to stop all queued animations of the selected element.

This parameter can only be used when the stopAll parameter is set.

The above is the detailed content of The use of stop() in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ​​the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

Five ways to effectively turn off the nohup command Five ways to effectively turn off the nohup command Mar 25, 2024 am 10:15 AM

Turning off a nohup command may be confusing to some users, especially those who are less familiar with Linux systems. In this article, we will discuss five effective ways to shut down the nohup command to help readers better manage their processes and free up resources. Method 1: Use the ps command to find the process and terminate it. The first method is to use the ps command to find the PID of the nohup process, and then use the kill command to terminate the process. First, find the PID of the nohup process using the following command: psa

See all articles