jquerytimers-提供3个函式:

everyTime(时间间隔,[计算器名称],函式名称,[次数限制],[等待函式程序完成])

//每1s执行函数test()
//1s=10
$('body').everyTime('1s','A',test,5);//计时器名称为A最多执行5次//每1s执行一次,执行无数次(默认为0),若抵达时间,函数还未执行完毕,则等待。
$('body').everyTime(10,'B',test,0,true);

oneTime(时间间隔,[计时器名称],呼叫的函式)

//10s=1das=100后执行test,计时器名称为C
$('body').oneTime(100,'C',test);

stopTime([计时器名称],[函式名称])

//停止body上的所有定时器
$('body').stopTime()
//停止body上名称为A的定时器
$('body').stopTime('A')
//停止body上呼叫test的所有定时器
$('body').stopTime(test)

jqueryTimers代码

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; color: #a5b2b9}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; min-height: 19.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; color: #596972}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; color: #b58a00}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; color: #2eafa9}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; color: #da6c34}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; color: #ad5cff}p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; color: #97a700}p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; color: #3c7400}p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; color: #596972; min-height: 19.0px}p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Consolas; color: #6b82d9}span.s1 {color: #596972}span.s2 {color: #6b82d9}span.s3 {color: #97a700}span.s4 {color: #b58a00}span.s5 {color: #ad5cff}span.s6 {color: #3c7400}span.s7 {color: #000000}span.s8 {color: #2eafa9}span.s9 {color: #d8a100}span.Apple-tab-span {white-space:pre}/*** jQuery.timers - Timer abstractions for jQuery* Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)* Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).* Date: 2009/02/08** @author Blair Mitchelmore* @version 1.1.2***/jQuery.fn.extend({everyTime: function(interval, label, fn, times, belay) {return this.each(function() {jQuery.timer.add(this, interval, label, fn, times, belay);});},oneTime: function(interval, label, fn) {return this.each(function() {jQuery.timer.add(this, interval, label, fn, 1);});},stopTime: function(label, fn) {return this.each(function() {jQuery.timer.remove(this, label, fn);});}
});jQuery.event.specialjQuery.extend({timer: {global: [],guid: 1,dataKey: "jQuery.timer",regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,powers: {// Yeah this is major overkill...'ms': 1,'cs': 10,'ds': 100,'s': 1000,'das': 10000,'hs': 100000,'ks': 1000000},timeParse: function(value) {if (value == undefined || value == null)return null;var result = this.regex.exec(jQuery.trim(value.toString()));if (result[2]) {var num = parseFloat(result[1]);var mult = this.powers[result[2]] || 1;return num * mult;} else {return value;}},add: function(element, interval, label, fn, times, belay) {var counter = 0;if (jQuery.isFunction(label)) {if (!times) times = fn;fn = label;label = interval;}interval = jQuery.timer.timeParse(interval);if (typeof interval != 'number' || isNaN(interval) || interval <= 0)return;if (times && times.constructor != Number) {belay = !!times;times = 0;}times = times || 0;belay = belay || false;var timers = jQuery.data(element, this.dataKey) || jQuery.data(element, this.dataKey, {});if (!timers[label])timers[label] = {};fn.timerID = fn.timerID || this.guid++;var handler = function() {if (belay && this.inProgress) return;this.inProgress = true;if ((++counter > times && times !== 0) || fn.call(element, counter) === false)jQuery.timer.remove(element, label, fn);this.inProgress = false;};handler.timerID = fn.timerID;if (!timers[label][fn.timerID])timers[label][fn.timerID] = window.setInterval(handler,interval);this.global.push( element );},remove: function(element, label, fn) {var timers = jQuery.data(element, this.dataKey), ret;if ( timers ) {if (!label) {for ( label in timers )this.remove(element, label, fn);} else if ( timers[label] ) {if ( fn ) {if ( fn.timerID ) {window.clearInterval(timers[label][fn.timerID]);delete timers[label][fn.timerID];}} else {for ( var fn in timers[label] ) {window.clearInterval(timers[label][fn]);delete timers[label][fn];}}for ( ret in timers[label] ) break;if ( !ret ) {ret = null;delete timers[label];}}for ( ret in timers ) break;if ( !ret ) jQuery.removeData(element, this.dataKey);}}}
});jQuery(window).bind("unload", function() {jQuery.each(jQuery.timer.global, function(index, item) {jQuery.timer.remove(item);});
});

更改其中的power,可以自设时间

  powers: {//1000=1s// Yeah this is major overkill...'ms': 1,'cs': 10,'ds': 100,'s': 1000,'das': 10000,'hs': 100000,'ks': 1000000}

jquery中的定时器-jquery.timers-1.1.2.js相关推荐

  1. jquery中live_14个jQuery Live Search插件

    jquery中live 实时搜索是一种增强的搜索表单,它使用AJAX技术在同一视图内提供结果或建议. 这与常规HTML输入字段不同,常规HTML输入字段从现代浏览器(例如Chrome,Firefox或 ...

  2. Jquery中日期插件jquery.datepick的使用

    jsp的代码: 1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 p ...

  3. Jquery中使用定时器setInterval和setTimeout

    直接在ready中调用其他方法,会提示缺少对象的错误,解决方法如下: 方法1. 函数不在$(function(){....})内,setInterval第一个参数为"showAtuto&qu ...

  4. jQuery中$(function(){})与(function($){})(jQuery)的区别

    首先,这两个函数都是在页面载入后执行的函数,其中两者的区别在于: 在jQuery中$(function(){})等同于jQuery(function(){}),另一个写法为jQuery(documen ...

  5. jQuery框架学习第二天:jQuery中万能的选择器

    jQuery框架学习第一天:开始认识jQuery jQuery框架学习第二天:jQuery中万能的选择器 jQuery框架学习第三天:如何管理jQuery包装集 jQuery框架学习第四天:使用jQu ...

  6. jQuery中的end()

    要说end(),我们就不得不说prevObject. 在jQuery中,每个jQuery对象都有一个prevObject属性 var $p = $('p'); 这个属性是做什么的呢? jQuery内部 ...

  7. jquery中的$(function(){})和document.ready(function(){})和jQuery(function () {}

    2019独角兽企业重金招聘Python工程师标准>>> 都表示的是DOM结构绘制完毕后就执行,不必等到加载完毕. 区别.只是简洁性.最后的那个是为了区分. 在jquery中 $ 其实 ...

  8. jquery中select操作append、prepend、remove、find、val、get、selectedIndex、attr、option

    全栈工程师开发手册 (作者:栾鹏) jquery系列教程2-DOM操作全解 jquery中select操作 jquery中select操作函数和字段包括append.prepend.remove.fi ...

  9. jquery中的循环技巧

    Js代码   作者:nuysoft/JS攻城师/高云 QQ:47214707 EMail:nuysoft@gmail.com 声明:本文为原创文章,如需转载,请注明来源并保留原文链接. 前记:本文收集 ...

最新文章

  1. 计算机基础知识同步训练,计算机应用基础:全国高等教育自学考试同步辅导/同步训练(非计算机专业公共基础课)最新版...
  2. Shiro的authc过滤器的执行流程
  3. 转 测试linux中expect的timeout参数的作用
  4. GPUImageMovieWriter录制视频问题
  5. k2ttl救砖_拆解刷breed变砖的斐讯K2P并修复
  6. 【ML】特征归一化、为什么归一化、归一化的方法、归一化方法选择依据
  7. 数据库(mysql)查询语句练习(中级)
  8. vue项目目录详细解读
  9. [ERROR NumCPU]: the number of available CPUs 1 is less than the required 2
  10. Definer 预言机攻击事件分析
  11. 用canvas画一个太极八卦图
  12. IDEA设置输入忽略大小写
  13. Swift UIView代码控制隐藏与显示
  14. 10月英语,美好的开始
  15. tcpdump抓包神器详细介绍
  16. Android OOBE开发
  17. 46、W25Q128 存储器工作原理
  18. Oracle EBS PO调用API修改一揽子发放行需求日期或数量引发单价变更
  19. 东北大学软件学院2021-2022软件需求设计与分析五子棋作业
  20. 计算机主机启动不了系统怎么办,电脑开机进不了系统怎么办?

热门文章

  1. Java游戏服务器开发之二十--xml配置文件
  2. 哈夫曼树的带权路径长度总结wpl
  3. Eclipse安装使用emmet插件
  4. 优秀公司是如何管理人的?
  5. 利用Java实现的一个简易的账号注册类
  6. win10微软远程桌面的bug(家庭版转专业版)
  7. 2022.1.13小记
  8. 热血三国攻略之养兵赚钱
  9. IPOs!2019年IPO会是创纪录一年吗?
  10. Python——八种数据类型