微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Timeout Interval Idle

程序名称:Timeout Interval Idle

授权协议: 未知

操作系统: 未知

开发语言:

Timeout Interval Idle 介绍

Creating Timeouts and Intervals

Javascript allows you to create Timeouts and Intervals using this Syntax:

setTimeout("alert('I waited 5 seconds!');",5000); setInterval("alert('I happen every 8 seconds');",8000);

These functions are very useful, but unfortunately they only accept code as a
string. This module allows you to use jQuery to create timeouts and intervals
that also accept functions, like this:

$.timeout(function() { alert('I waited 5 seconds'); }, 5000); $.interval(function() { alert('I happen every 8 seconds'); }, 8000);

You can also create Timeouts and Intervals from predefined functions:

function Now() { alert('Now!'); } $.timeout(Now, 5000); $.interval(Now, 8000);

Clearing Timeouts and Intervals

Javascript allows you to create and clear Timeouts and the Intervals using the
following sytax:

var to = setTimeout("alert('I waited 5 seconds!');",5000); var it = setInterval("alert('I happen every 8 seconds');",8000); clearTimeout(to); clearInterval(it);

Using this plugin, the same can be done like this:

var to = $.timeout(function() { alert('I waited 5 seconds'); }, 5000); var it = $.interval(function() { alert('I happen every 8 seconds'); }, 8000); $.clear(to); $.clear(it);

Creating Idle Timeouts

In addition to the above functionality, this plugin provides a new type of
timed function, the Idle Timeout. Every time you create a new Idle Timeout,
any prevIoUs Idle Timeout is cleared. This means that you can make an event
happen X seconds after the last time this functions is called. For example:

<input type="text" id="body" onkeypress="$.idle(function() { alert($('#body').val()); }, 3000);" />

The above code will set an Idle Timeout (and clear the last one) every time
the user types into the input Box. 3 seconds after the last key is pressed,
the idle function will run and the contents of the input Box will be alerted.

Timeout Interval Idle 官网

http://plugins.jquery.com/project/timeout_interval_idle

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐