Coder Social home page Coder Social logo

jquery-simple-timer's Introduction

Simple.Timer

A jQuery plugin that creates a countdown timer.

Usage

Set the desired duration using either data-seconds-left or data-minutes-left data attributes.

<div class='timer' data-minutes-left=3></div>
<div class='timer' data-seconds-left=180></div>

Then start the timer with:

$('.timer').startTimer();

The plugin creates <div> elements with the following CSS classes by default:

  • jst-hours
  • jst-minutes
  • jst-seconds
  • jst-clearDiv
  • jst-timeout (added only when the timer is finished)

Here's an example of the HTML of a finished timer:

<div class="timer jst-timeout" data-seconds-left="3">
  <div class="jst-hours">00:</div>
  <div class="jst-minutes">00:</div>
  <div class="jst-seconds">00</div>
  <div class="jst-clearDiv"></div>
</div>

The default CSS classes can be used to style the timer or we can specify custom classes via the classNames option. Like this:

$('.timer').startTimer({
  classNames: {
    hours: 'myClass-hours',
    minutes: 'myClass-minutes',
    seconds: 'myClass-seconds',
    clearDiv: 'myClass-clearDiv',
    timeout: 'myClass-timeout'
  }
});

Options

For more options, checkout http://csouza.me/jQuery-Simple-Timer/ and some more examples.

Install

This plugin can be installed manually from github or via npm.

Manual

Clone the repository and reference the jquery.simple.timer.js file from your html:

<script src="jquery.js"></script>
<script src="jquery.simple.timer.js"></script>

npm

To install from npm, run:

npm install jquery-simple-timer --save

jQuery is NOT installed automatically. We need to install jQuery (npm install jquery --save) and then pass it as an argument to the return value of the require() statement. Here's an example:

// file: client.js
"use strict";

let $ = require("jquery");
require("jquery-simple-timer")($); // passing jQuery as argument

$(function(){
  $('.timer').startTimer();
});

Tests

Open tests/index.html

Contributors

jquery-simple-timer's People

Contributors

alexsilva avatar asciicat avatar caike avatar dependabot[bot] avatar roshiro avatar vleong2332 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-simple-timer's Issues

Accept custom element classes via options.

Accept custom classes for span elements (hours, minutes, seconds and clearDiv) and for timeout via a classNames option. Like this:

  $('#timer').startTimer({
    classNames: {
      hours: 'banana-hours',
      minutes: 'banana-minutes',
      seconds: 'banana-seconds',
      clearDiv: 'banana-clearDiv',
      timeout: 'banana-timeout'
    }
  });

missed onComplete event when computer is asleep

Using Simple-Timer as an auto-logout for a private database I encountered an issue: e.g. the timer is set to 30', the computer goes to standby at 28' and is re-activated 4 minutes later, the timer is at 23h 58', having missed the onComplete event at 0'00''.
Inserting a new line 125
if (timeLeft < 0) timeLeft = 0;
did solve this for me.

how to limit the number of timer loop?

Hi,
I want to specify the number of the timer loop! I can set the loop interval but I don't know how to limit the loop number?!
any idea?
thanks
Mansour

how can i stop the timer

hi,excuse me , im working with your timer but i dont know how can i stop the timer ? please
thanks
sincerely

Any chance how to show days left?

Hi, thanks for your script - it is easy and working as expected. Only one thing I miss is posibble to show days left. I've tried to extend plugin but it is broken :) Would be fine to have this option.

Unable to re-set timer to different duration.

Hi, i tried using the timer with data-seconds-left =2 , after the 2 seconds run out, i run some ajax, after ajax returns, i want to run the timer with a 10 seconds duration.
Any idea on how to make this possible?
The timer seems to run back the 2 seconds timer even after i change the data-seconds-left to 10 seconds via $('#timer').attr('data-seconds-left',10);
Thanks.

Jquery Timer is not working in IE browser

Hi Carlos,

I am using this code . It is not working in any version of IE. Although it works fine in all other browsers like Mozilla,Chrome and Safari. Could you provide any solution.

Thanks,
Deepak

Ie 11 not working

not working in ie 11. im getting this error

Object doesn't support property or method 'isInteger'

Bump version

Bump version so that bower sees new features.

StopTimer and clearInterval

Hi!!
I have a timer and i want a function to stop timer.

var inter = $(`#my-record-${id} .timer`).startTimer();

But the library don't have any function to stop.

Thanks

Add clearInterval function to element

From this

$('.timer').startTimer({
  onComplete: function(element){
    clearInterval(element.intervalId);
    element.addClass('timeout');
  }
});

to this

$('.timer').startTimer({
  onComplete: function(element){
    element.clearInterval();
    element.addClass('timeout');
  }
});

Add option to loop forever

Add option to repeat forever.

$('timer').startTimer({
  loop: true, // restarts timer after each time out
  loopInterval: 5, // waits 5 seconds before starting timer again
})

timer pause and play

how to pause the timer by clicking on some button without clicking on the timer ? I've tried all the suggestion you gave and from the previous issues solved. But it didn't help me out. Please response ASAP.

Add restart example to the docs.

Add example showing how to restart the timer from the onComplete function and with a new value for timeout. Mention the .attr() method will not work and we must use the .data() method instead. See #20

on almost complete

Is it possible to add an "on almost complete" to the mix so the counter gets other styles when the time is almost up?

Ho to debugg this?

I used your plugin severyl times but no it's not working anymore.

I load it like this:

<div class="sunLocDuration timer itIsDay" data-seconds-left="19999"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/caike/jQuery-Simple-Timer/1bc86823/jquery.simple.timer.js"></script>
<script>
  $( document ).ready(function() {
    $('.timer').startTimer();
  });
</script>

This does nothing. It doesnt even throw an error. It simply doesn't work. What's the catch here?

Set data-seconds-left value using jquery on page load

Thanks for this plugin its really helpful. Can you please tell me how can I set the value using jquery of this below tag. I cannot give time to data-seconds-left with my h4 tag. Its remaining time is coming from the server-side. So, I need to assign it on page load.

if data-minutes-left="0"

I use your Time as a Sun clock which counts down the seconds to sunset.

If the data-minutes-left="0"is set to 0 (which happens after sunset) there is nothing displayed anymore. Is it somehow possible to keep it in the 00:00:00 format?

"jQuery is not defined" when using the NPM installation method.

I followed the NPM installation method:

"use strict";
let $ = require("jquery");
require("jquery-simple-timer")($);

$(() => {
  $('.timer').startTimer();
});

and it says jQuery is not defined.

Not sure if this has something to do with the fact that Im transpiling ES6 code using babelify and browserify.

Note: The jQuery is not defined comes from the plugin file itself "jquery.simple.timer.js:189"

Thanks in advance!

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.