Change scrolling titles based on current time

I'm making a website that changes a lot based on the time of day. I'm currently using a "title scroller" to animate text along the title of the website. Based on my current time of day (I live in Belgium), I would like the title to change.

For example:

From 00:00?8:30, the title should say "Zzzz?"

From 8:30?00, the title should say "Welcome to my online home!"

I've been using this script to create a scrolling title, but honestly I have no idea how to adapt this so that it changes based on my current time (which is CET).

(function titleScroller(text) {
    document.title = text;
    setTimeout(function () {
        titleScroller(text.substr(1) + text.substr(0, 1));
    }, 100);
}(" Zzzz? "));

Answers 1

  • If you want to set time according to your timeline, you need a server-side code. If not, just use $.now() to get the local timestamp.

    You can get the hour of the day (which is your only concern according to your plan) by (new Date).getHours().

Related Articles