Basic setTimeout() Example

setTimeout(function() {
      // Do something after 5 seconds
}, );

Tip: you can use the ClearTimeout() function to clear any timer values previously stored.

timeout = setTimeout('timeout_trigger()', );
clearTimeout(timeout);

More setTimeout() Examples

jQuery(document).ready(function () {
    //hide a div after 3 seconds
    setTimeout( "jQuery('#div').hide();", );
});

Or in a different way:

jQuery(document).ready(function () {
    //hide a div after 3 seconds
    setTimeout(function(){ jQuery("#div").hide(); }, );
});
<!-- show a message for  seconds after you click the button -->
<input type="button" value="click me"
 onclick="setTimeout('window.alert(\'Hello!\')', 2000)" />

Or as a function:

<script language="Javascript">

function timeout_trigger() {
    window.alert('Hello!');  
} function timeout_init() {
    setTimeout('timeout_trigger()', );
} </script>
<input type="button" value="click me" onclick="timeout_init()" />

案例:

var timeover;
var timeout; $(".namelistul li img").mouseover(function(){
clearTimeout(timeover);
clearTimeout(timeout);
var namelistli = $(this).parent();//父节点
timeover = setTimeout(function() {
if(namelistli.has("span").length==){
var $span = $("<span class='namelistdel' style='position:absolute;'><img src='/images/select_imgbt.png'></span>");
$(namelistli).prepend($span); }
}, );
//删除其他的span
namelistli.siblings().find("span").remove(); }); $("body").on("mouseout", '.namelistdel', function(){
clearTimeout(timeover); //鼠标离开解除延迟
clearTimeout(timeout);
timeout = setTimeout(function() {
$(".namelistdel").remove();
}, );
});

setTimeout()使用的更多相关文章

  1. setTimeout 的黑魔法

    setTimeout,前端工程师必定会打交道的一个函数.它看上去非常的简单,朴实.有着一个很不平凡的名字--定时器.让年少的我天真的以为自己可以操纵未来.却不知朴实之中隐含着惊天大密.我还记得我第一次 ...

  2. 你所不知道的setTimeout

    JavaScript提供定时执行代码的功能,叫做定时器(timer),主要由setTimeout()和setInterval()这两个函数来完成.它们向任务队列添加定时任务.初始接触它的人都觉得好简单 ...

  3. setTimeout那些事儿

    一.setTimeout那些事儿之单线程 一直以来,大家都在说Javascript是单线程,浏览器无论在什么时候,都且只有一个线程在运行JavaScript程序. 但是,不知道大家有疑问没——就是我们 ...

  4. 深入理解定时器系列第一篇——理解setTimeout和setInterval

    × 目录 [1]setTimeout [2]setInterval [3]运行机制[4]作用[5]应用 前面的话 很长时间以来,定时器一直是javascript动画的核心技术.但是,关于定时器,人们通 ...

  5. 前端开发:setTimeout与setInterval 定时器与异步循环数组

    前端开发:setTimeout与setInterval 定时器与异步循环数组 前言: 开通博客园三个月以来,随笔记录了工作中遇到的大大小小的难题,也看过无数篇令人启发的文章,我觉得这样的环境是极好的, ...

  6. javascript函数setInterval和setTimeout的使用区别详解

    setTimeout和setInterval的使用 这两个方法都可以用来实现在一个固定时间段之后去执行JavaScript.不过两者各有各的应用场景. 方 法 实际上,setTimeout和setIn ...

  7. UNITY实现FLASH中的setTimeout

    setTimeout是一个很方便的DELAY处理方法 if (this.startUpDelay > 0){            StartCoroutine(DelayedStart()); ...

  8. setTimeout和setInterval从入门到精通

    我们在日常web前端开发中,经常需要用到定时器方法. 前端中的定时器方法是浏览器提供的,并不是ECMAScript规范中的.是window对象的方法. 浏览器中的定时器有两种, 一种是每间隔一定时间执 ...

  9. setTimeout和setInterval定时器使用详解测试

    var len=4; while(len--){ var time=setTimeout(function(){ console.log(len); },0); console.log(time); ...

  10. setTimeout 和 throttle 那些事儿

    document.querySelector('#settimeout').onclick= function () { setTimeout(function () { console.log('t ...

随机推荐

  1. The Angles of a Triangle

    The Angles of a Triangle You are given the lengths for each side on a triangle. You need to find all ...

  2. java设计模式--结构型模式--享元模式

    享元模式 概述 运用共享技术有效地支持大量细粒度的对象. 适用性 当都具备下列情况时,使用Flyweight模式: 1.一个应用程序使用了大量的对象. 2.完全由于使用大量的对象,造成很大的存储开销. ...

  3. 【转】ubuntu下解压缩zip,tar,tar.gz和tar.bz2文件

    原文网址:http://blog.sina.com.cn/s/blog_5da93c8f0101h1uj.html 在Linux下面如何去压缩文件或者目录呢? 在这里我们将学习zip, tar, ta ...

  4. 利用智能手机(Android)追踪一块磁铁(三)

    更新磁铁追踪算法的源代码,Android Studio项目工程 github地址:https://github.com/amazingyyc/MagnetLocate 说明:将磁铁的位置信息封装成消息 ...

  5. poj 3684 Physics Experiment(数学,物理)

    Description Simon ), the first ball is released and falls down due to the gravity. After that, the b ...

  6. hdu 5612 Baby Ming and Matrix games(dfs暴力)

    Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...

  7. redis实现spring-data-redis整合

    java之redis篇(spring-data-redis整合)  博客链接网址:http://www.cnblogs.com/yjmyzz/tag/redis/ redis的知识:官网 1,利用sp ...

  8. Linux 编译安装 apache 2.4

    在安装apache之前需要准备一些必要的依赖包 gcc安装: #yum install -y gcc gcc-c++安装: #yum install gcc-c++  apr安装: 下载包:apr-1 ...

  9. Remastersys备份linux系统ISO镜像

    1. 安装Remastersys 利用Ubuntu Software Center安装,修改sources.list文件,在文件末尾加入下面三行,添加软件源, #Rsudo remastersys d ...

  10. javascript 多图无缝切换

    思路只要是ul移动前,首先将当前显示的li克隆岛ul最后,当每次运动执行完毕后,再将前面的li删除,如此循环. <!DOCTYPE html> <html> <head& ...