jQuery If Statement and get time
Hi i am using a script which is a countdown timer - how in jQuery do i watch the countdown timer and check whether is over, in between or under a certain amount of milliseconds?
Based on the documentation and the author (the author wasn't very helpfull and refuses to help). i have came up with this.
what i want to achieve is a simple class which is added to a div based on how much time is left.
if the time left is greater than 10 minutes change div to the color green.
if the time left is between 1-10 minutes change div to orange and finally.
if the time left is under 1 minute change div to red.
I've created a fiddle of how it currently looks
there's 3 class which i want to add to the traffic-light div .green, .orange and .red based on the info above
- $(document).ready(function(){
- $('[data-countdown]').each(function() {
- var $this = $(this), finalDate = $(this).data('countdown');
- $this.countdown(finalDate, function(event) {
-
- var format = '%-Hh : %-Mm : %-Ss';
-
- if (event.offset.seconds > 600000) { //if the time is over 10minutes
- $("table").find(".traffic-light").addClass( "green" );
- } else if (event.offset.seconds > 60000-600000) { //if the time is between 1 and 10 minutes
- $("table").find(".traffic-light").addClass( "orange" );
- } else if (event.offset.seconds > 0-60000) { //if the time is between 0 and 1 minute
- $("table").find(".traffic-light").addClass( "red" );
- }
-
- $(this).html(event.strftime(format));
- });
- });
- });