Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize automatic hiding for five seconds by jquery

Shulou Source: shulou.com Published: 2022-05-31 17:05:31 09月11日 Update

This article mainly explains "jquery how to achieve five-second auto-hiding". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "jquery how to achieve five-second auto-hiding".

Two methods: 1. "setTimeout (function () {specify object .hide ();}, 5000);" statement, which achieves the delay effect by setting a timer. 2. Use the "specify object .delay (5000). FadeOut ();" statement to achieve the effect by delaying the execution time of the code.

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

Jquery realizes automatic hiding for five seconds

1. Use the setTimeout () method

Execute the function () method after setting it for 5 seconds using the setTimeout () method

Within the function () method, use the hide () method to implement the specified element.

$(document) .ready (function () {$("button") .click (function () {setTimeout (function () {$("div"). Hide ();}, 5000);});})

Description:

The setTimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds.

SetTimeout () executes code only once. If you want to call multiple times, use setInterval () or have code itself call setTimeout () again.

2. Use delay () to set the automatic hiding of elements for five seconds

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

.block {width: 200px; height: 200px; background: brown; cursor: pointer; transition: 0.8s } $(document) .ready (function () {$("button") .click (function () {$("div") .delay (5000) .fadeOut () );})

Hide div elements for 5 seconds

Thank you for your reading, the above is the content of "how to achieve five-second automatic hiding in jquery". After the study of this article, I believe you have a deeper understanding of how to achieve five-second automatic hiding in jquery. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Methods elements learning delay content objects effects statements code again functions timers that is ideas situations tutorials articles time more version Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Linux vpn Shulou Information Microsoft