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)".
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)
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)
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>
Output result:
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!