Home > Web Front-end > Front-end Q&A > How to make jquery disappear after two seconds

How to make jquery disappear after two seconds

WBOY
Release: 2022-01-10 16:49:22
Original
1684 people have browsed it

In jquery, the delay() and hide() functions can be used to achieve the effect of the element disappearing after two seconds. The delay() function is used to set the delay time for the execution of the next item in the queue. The hide() function Used to hide the selected element, the syntax is "$(element).delay(2000).hide(200)".

How to make jquery disappear after two seconds

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How jquery disappears after two seconds

The delay() method sets a delay for the execution of the next item in the queue.

Syntax

$(selector).delay(speed,queueName)
Copy after login

Parameters

speed Optional. Specifies the speed of the delay. Possible values: milliseconds, "slow", "fast"

queueName Optional. Specifies the name of the queue. Default is "fx", the standard effects queue.

hide() method hides the selected element.

Tip: This is similar to the CSS property display:none.

Note: Hidden elements will not be fully displayed (no longer affect the layout of the page).

Tip: To show hidden elements, check out the show() method.

Grammar

$(selector).hide(speed,easing,callback)
Copy after login

The example is as follows:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
    $(function(){
        $("#dianji").click(function(){
            $("#disappare").delay(2000).hide(200);
        });
    })
</script>
</head>
<body>
    <div id="content">
        <button id="dianji">点击</button>
        <div id="disappare">
            <p>点击2秒后会自动消失</p>
        </div>
    </div>
</body>
</html>
Copy after login

Output result:

How to make jquery disappear after two seconds

Related video tutorial recommendations: jQuery video tutorial

The above is the detailed content of How to make jquery disappear after two seconds. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template