jquery settimeout Implementation of event function delay loading instance

Source: Internet
Author: User

In the Window Load event, we can delay processing so that some events can be handled when the page loads.

The code is as follows Copy Code

(function fn () {
Fn.now = +new Date;
$ (window). Load (function () {
if (+new date-fn.now < 1000) settimeout (FN, 1000);
Do something

If we want to perform a bit of latency to display a mask layer (just for example) when the Load event executes, refer to the next CSS mask code. As follows:

The code is as follows Copy Code

(function fn () {
Fn.now = +new Date;
$ (window). Load (function () {
if (+new Date-fn.now < 3000) settimeout (FN, 3000);
$ ("#mask"). Show ();
$ ("#mask"). Hide ();

Here's a look at a settimeout and jquery implementation of the delay loading

  code is as follows copy code

<div class= "Toolbarframe" style= "Display:none;" ><a href= "http://www.111cn.net" target=_blank><a class= "Bigad_close" > Close </a></div>
$ (function () {
  SetTimeout (' $ (' Toolbarframe '). Show ("Slow") ', 2000;
 $ (". Bigad_close"). Click (function () {
  $ (". Toolbarframe"). Hide ("slow");
 //settimeout (' $ ('. Toolbarframe '). Hide ("slow") ', 12000);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.