Countdown Timer That Starts On The First Visit - Timer.js

File Size: 3.18 KB
Views Total: 1849
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Countdown Timer That Starts On The First Visit - Timer.js

Timer.js is a countdown timer that automatically starts when users first visit your site, and runs continuously in the background until reaching the specified end time.

Built with jQuery library and HTML5 local storage.

How to use it:

1. Include the main script timer.js after loading the latest jQuery library (slim build is recommended).

<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/timer.js"></script>

2. Create a container to hold the countdown timer.

<div class="timer"></div>

3. Initialize the countdown timer and specify the end time as follows. Note that the end time should be a JS array containing the dates, hours, minutes, and seconds you want to count down.

// 120 minutes
set_timer($('.timer'), [
  0, // date
  0, // hour
  120, // minute
  0 // second
]);

4. Trigger a function after the countdown timer has finished.

// 120 minutes
set_timer($('.timer'), [
  0, // date
  0, // hour
  120, // minute
  0 // second
], function(block) {
  // do something
});

This awesome jQuery plugin is developed by Somonator. For more Advanced Usages, please check the demo page or visit the official website.