Trouble setting the date on countdown timer

I am currently trying to implement a countdown timer using the flipclockjs library. I have managed to make it work properly when using intervals, but I am facing issues when attempting to use setDate or similar functions.

I apologize if this question seems basic, as I am still relatively new to these concepts. Any assistance would be greatly appreciated. Thank you!

Below is the code snippet:

<html>
<head>
    <link rel="stylesheet" href="../compiled/flipclock.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="../compiled/flipclock.js"></script>
</head>
<body>

<div class="clock" style="margin:2em;"></div>
<div class="message"></div>

<script type="text/javascript">
    var clock;

    $(document).ready(function() {
        var clock;
        clock = $('.clock').FlipClock({
            clockFace: 'DailyCounter',
            autoStart: false,
            callbacks: {
                stop: function() {
                    $('.message').html('The clock has stopped!')
                }
            }
        });

        clock.setTime(220880);
        clock.setCountdown(true);
        clock.start();
    });
</script>

</body>

Answer №1

If you want to schedule a date and calculate the time difference in seconds between that date and the current date, you can use the FlipClock library to display a countdown timer.

var clock = $('.clock').FlipClock(diff ,{...});

$(document).ready(function() {
      var d = new Date();
      d.setDate(d.getDate()+2);
      var curd = new Date();
      var diff = (d.getTime() - curd.getTime()) / 1000; //divide by 1000 to transform milliseconds in seconds
  
      var clock = $('.clock').FlipClock(diff,{
          clockFace: 'DailyCounter',
          autoStart: true,
          countdown: true,
          callbacks: {
              stop: function() {
                  $('.message').html('The clock has stopped!')
              }
          }
      });
  });
<html>
<head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flipclock/0.7.8/flipclock.css">

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/flipclock/0.7.8/flipclock.js"></script>
</head>
<body>
<div class="clock" style="margin:2em;"></div>
<div class="message"></div>
</body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Numerous JavaScript modules incorporated within Ember.js

I am in the process of creating a prototype Single Page Application using Ember.js. To speed up development, I am currently utilizing three separate JavaScript components: a calendar/todo list, a JavaScript clock, and a jQuery plugin. My goal is to have th ...

design a secure container in html

In the process of creating a helper function that is utilized by a templating library, I have run into an issue. Currently, my helper generates a div with a specific guid id which acts as a placeholder. Additionally, it includes a script that makes a call ...

Error message: Unexpected token "(" in the asynchronous aspect of Meteor

Currently running meteor version 1.5.1, I am facing a bug while attempting to import an npm module (kraken-api) on the server side: import KrakenClient from 'kraken-api'; > W20170726-22:02:48.177(2)? (STDERR) packages/modules.js:677 ...

Troubleshooting: xPages radio button group onchange event malfunctioning

I have created a simple page with a listbox control that should update its values based on the selection made in a radiobutton group. The listbox is connected to a scope variable array as its data source. However, I am experiencing an issue where the lis ...

Does Jquery AJAX send back raw data or HTML ready for use?

I'm currently developing a mobile app using Jquery Mobile. In order to populate the app with data, I need to make requests to an API and display the information within the app. At this point, I have two possible options: The API returns JSON data ...

Displaying PHP output within a JavaScript expression

Let's dive into a scenario involving a basic HTML document and some JavaScript that's loaded within it: <!-- doc.html --> <!doctype html> <html lang="en"> <head> <script type="text/javascript" src=" ...

Jquery's remove function fails to function correctly when used on a cloned element

I am facing an issue where I have a list of rows that need to be deleted. However, when I attempted to use jQuery's remove function, it only removed the original row and not its clone. My goal is for the parent element of the parent to be removed when ...

Tips for making a multiselect dropdown menu using bootstrap

I am working on a JavaScript application that parses data and displays it to users in a table generated by JavaScript. I am looking for a simple way to allow users to choose which fields to display in the table using a dropdown list or something similar. I ...

"Upon invoking the console log, an empty value is being returned when attempting to access the

Why is console.log returning a blank line when trying to retrieve the value of a text input variable? HTML <label for="subject">Subject</label> <input type="text" id=" ...

What causes scope to be undefined in Angular?

Using ionic to develop a hybrid app has been a smooth experience, especially with android! This is my login HTML: <body ng-app="starter"> <head> <script src="phonegap.js"></script> </head> <ion-header-ba ...

The automatic table refresh feature failed to function

I need to update my table every 5 seconds. Currently, I have this script: <script type="text/javascript> $(document).ready(function(){ refreshTable(); }); function refreshTable(){ $('#content').load('refres ...

`No valid form submission when radio buttons used in AngularJS`

Within my form, I have a single input text field that is required (ng-required="true") and a group of radio buttons (each with ng-model="House.window" and ng-required="!House.window"). Interestingly, I've discovered that if I select a radio button fir ...

Transforming a Typescript class instance into a JavaScript object

Here is the code snippet I am working with: class A{ test: string constructor(test: string){ this.test = test } } const a = new A("hi") console.log(a) This is what the output looks like: A { test: 'hi' } However, when at ...

Deciphering the ins and outs of the jQuery each function - Surprising

I'm currently trying to understand how the each function works. In this specific scenario demonstrated in this fiddle here, my goal is to iterate through the selected elements of a list box individually. Initially, I anticipated an output like this: ...

How can I create a tooltip or something similar for an HTML input field?

Seeking a solution for adding additional information to an HTML input field while typing or hovering over it. Attempted the following code snippet: <input type="text" onmouseover="window.status='hello world'; return true;" name="TextInput" ta ...

AngularJS Bootstrap Datepicker populating date from input field

I'm currently utilizing Bootstrap for my web application. I've developed a method that initializes all input fields of type date with a class called form_datetime: function initDatepicker(){ $(".form_datetime").datepicker({ ...

What is the process for creating unit tests for a method that utilizes the @Transaction() decorator?

I am currently using NestJS 6 and TypeORM to interact with a MySQL database. While attempting to write unit tests for a method that utilizes the @Transaction() and @TransactionManager() decorators, I encountered the following error message: ConnectionNotF ...

Arranging divs using inline-block display. How to adjust the heights consecutively?

After much searching and attempting, I am still unable to achieve a simple task. My goal is to apply display inline-block to some divs while aligning them in a row, similar to the image below: https://i.sstatic.net/iLhLS.png The issue arises when number ...

Creating a file by piping the output of an asynchronous HTTP request while utilizing async await method

I have been diligently following the instructions and conducting thorough research for a whole day to figure out how to use a pipe to compile an Excel spreadsheet that is fetched through an API call. I managed to get part of the way in saving it, but unfor ...

Angular.js: how to filter an ng-repeat by a missing key/value pair

How can I filter the ng-repeat to only display rows where all key/value pairs are present? HTML <div ng-app="myApp" ng-controller="oneController"> <table class="table table-bordered table-hover"> <thead> <tr> <th> ...