jQuery Timers插件

来源:互联网 发布:淘宝女郎叶青 编辑:程序博客网 时间:2024/06/08 14:14

JQuery
Timers
提供了三个函式
1. everyTime(时间间隔, [计时器名称], 函式名称, [次数限制], [等待函式程序完成])
2. oneTime(时间间隔, [计时器名称], 呼叫的函式)
3. stopTime ([计时器名称], [函式名称])

例子:

var times = chunks.length;$(document).everyTime(1000, function(i) {  processChunk(i);}, times);

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

//每1秒执行函式test()function test(){   //do something...}$('body').everyTime('1s',test);//每1秒执行$('body').everyTime(10,function(){//do something...});//每1秒执行,并命名计时器名称为A$('body').everyTime(10,'A',function(){//do something...});//每20秒执行,最多5次,并命名计时器名称为B$('body').everyTime(200,'B',function(){//do something...},5);

例子:

$("#close-button").click(function() {  $(this).oneTime(1000, function() {    $(this).parent(".main-window").hide();  });});$("#cancel-button").click(function() {  $("#close-button").stopTime();}); 

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

//倒数10秒后执行$('body').oneTime(100,function(){//do something...});

例子:

$("#close-button").click(function() {  $(this).oneTime(1000, "hide", function() {    $(this).parent(".main-window").hide();  });});$("#cancel-button").click(function() {  $("#close-button").stopTime("hide");});

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

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

转载自http://www.cnblogs.com/linzheng/archive/2010/11/17/1880282.html

0 0
原创粉丝点击