/    Sign up×
Community /Pin to ProfileBookmark

How to show that the timer is “working”?

I am trying to do a Javascript timer with hours and minutes. I think this code will work (AFAIK):

https://jsfiddle.net/ur9m7ac8/27/

BUT. I need “something” that indicates that the timer is “working” as the interval is one minute. It appears that nothing happens.

Any tip how to create a “I am running….” dot or dots or whatever?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@sibertauthorJul 22.2020 — I found one way, but it must be a simpler or smarter way.
  • 1. The value "diff" could be even several times and therefore flashes irregularily.

  • 2. The if statement could be smarter.


  • https://jsfiddle.net/pk21vuhm/4/

    ``<i>
    </i>function display() {
    now = new Date().getTime();

    if (savedtime) {
    diff = (now - begin) + savedtime;
    } else {
    diff = now - begin;
    }

    if ((diff % 2) == 0) dot = ".";
    if ((diff % 2) != 0) dot = " ";

    difftxt = (diff / 1000 / 60 / 60);
    difftxt = difftxt.toFixed(2)
    displaytime.innerHTML = difftxt + dot;
    }<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @sibertauthorJul 22.2020 — I found a smarter way to write an if statement, but it still flashes irregularly due to the random diff value

    https://jsfiddle.net/p94a12q8/10/

    How can I get it to flash more regularly?

    ``<i>
    </i>function display() {
    now = new Date().getTime();

    if (savedtime) {
    diff = (now - begin) + savedtime;
    } else {
    diff = now - begin;
    }

    displaytime.style.color = (diff % 2) ? "#888" : "#fff";

    difftxt = (diff / 1000 / 60 / 60);
    difftxt = difftxt.toFixed(2)
    displaytime.innerHTML = difftxt;

    }<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @sibertauthorJul 22.2020 — Finally I found a rather simple solution:

    ``<i>
    </i>function display() {
    now = new Date().getTime();

    if (savedtime) {
    diff = (now - begin) + savedtime;
    } else {
    diff = now - begin;
    }

    onoff = onoff + 1
    displaytime.style.color = (onoff % 2) ? "#888" : "#fff";

    difftxt = (diff / 1000 / 60 / 60);
    difftxt = difftxt.toFixed(2)
    displaytime.innerHTML = difftxt;
    }<i>
    </i>
    ``


    https://jsfiddle.net/k3t5r1xu/20/

    Any tip how to improve it further?
    ×

    Success!

    Help @sibert spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 3.29,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,

    tipper: Anonymous,
    tipped: article
    amount: 10 SATS,
    )...