| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
10年前发布

jQuery 计时器插件:jQuery Timer

jQuery Timer 可以在任意 HTML 元素开始,停止,恢复或者移除一个计时器,并且可以在设定的时间或者间隔一定的时间得到提醒通知。 

Demo & Instructions | Download

How to use

In your web page:

<script src="path/to/jquery.js" type="text/javascript"></script>  <script src="path/to/timer.jquery.js"></script>  <script>  (function($) {      //start a timer    $("#div-id").timer();    }());  </script>

Usage Instructions

Start a timer from 100 seconds (1:40)

$("#div-id").timer({      seconds: 100  });

Methods available on an initialized timer:

//pause an existing timer  $("#div-id").timer('pause');    //resume a paused timer  $("#div-id").timer('resume');    //remove an existing timer  $("#div-id").timer('remove');  //leaves the display intact    //get elapsed time in seconds  $("#div-id").data('seconds');

Timed Events

Start a timer and execute a function after a certain duration. You can use this to simulate a timed event.

//start a timer & execute a function in 5 minutes & 30 seconds  $('#div-id').timer({      duration: '5m30s',      callback: function() {          alert('Time up!');      }  });

Start a timer and execute a function repeatedly at a certain duration. You can use this to sync current state with the backend by initiating a ajax request at regular intervals.

//start a timer & execute a function every 2 minutes  $('#div-id').timer({      duration: '2m',      callback: function() {          alert('Why, Hello there');  //you could have a ajax call here instead      },      repeat: true //repeatedly calls the callback you specify  });

Duration Syntax

When you initialize a timer with the duration and callback parameters, the timer plugin executes the callback function at the set duration. The syntax for specifying the duration is verbose. h for hours. m for minutes and s for seconds. Here are some examples:

'3h15m'     // 3 hours, 15 minutes  '15m'       // 15 minutes  '30s'       // 30 seconds  '2m30s'     // 2 minutes 30 seconds  '2h15m30s'  // 2 hours 15 minutes and 30 seconds

jQuery 计时器插件:jQuery Timer

项目主页:http://www.open-open.com/lib/view/home/1418096000808

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1418096000808.html
其他jQuery插件 jQuery插件 jQuery Timer