GithubHelp home page GithubHelp logo

sweetymeow / timer.jquery Goto Github PK

View Code? Open in Web Editor NEW

This project forked from walmik/timer.jquery

0.0 2.0 0.0 1.17 MB

jQuery Timer: Start/Stop/Resume/Remove pretty timer inside any HTML element.

Home Page: http://jquerytimer.com

License: MIT License

JavaScript 82.72% HTML 12.16% CSS 5.12%

timer.jquery's Introduction

jQuery Timer plugin

  • Lightweight, well tested Build Status jQuery pretty timer plugin
  • Start, Pause, Resume and Remove a timer inside any HTML element.
  • Get notified after specific time or at regular intervals.
  • Click and edit time while timer is running!

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

To start a timer with options:

$("#div-id").timer(options);

Options for timer:

$("#div-id").timer({
	seconds:	{Int},		// The number of seconds to start the timer from
	duration: 	{String},	// The time to countdown from. `seconds` and `duration` are mutually exclusive
	callback: 	{Function},	// If duration is set, this function is called after `duration` has elapsed
	repeat: 	{Bool},		// If duration is set, `callback` will be called repeatedly
	format:		{String}	// Format to show time in
});
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
Format Syntax

By default the timer displays the biggest whole unit. Examples:

  • seconds: 50 will show as 50 sec
  • seconds: 63 will show as 1:03 min
  • seconds: 3663 will show as 1:01:03

If you want to customize the format in which the timer displays time, use the format option. Available formats the timer understands are:

Format Description Example
%h Non-zero padded Hours %h hours gives 3 hours
%m Non-zero padded Minutes unless number of minutes is greater than 60 %h:%m minutes gives 0:6 minutes or 1:06 minutes
%s Non-zero padded Seconds unless number of seconds is greater than 60 %h:%m:%s gives 0:0:6 or 0:1:06 or 1:01:06
%H Zero padded Hours %H hours gives 03 hours
%M Zero padded Minutes %H:%M minutes gives 00:06 minutes
%S Zero padded Seconds %H:%M:%S gives 00:00:06

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.

//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
});

Start a timer and execute a function repeatedly at a certain duration and then reset the timer.

//start a timer & execute a function every 2 minutes
$('#div-id').timer({
	duration: '2m',
	callback: function() {
		$('#div-id').timer('reset');
	},
	repeat: true //repeatedly calls the callback you specify
});

timer.jquery's People

Contributors

walmik avatar

Watchers

James Cloos avatar Wendy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.