lundi 23 mai 2016

Make a website title scroll in HTML

I would like my website title in tabs to scroll, when the text is long enough to make it scroll and only until the end of the title, instead of making it continue scrolling like a wheel(?).

Basically, as an example, imagine the title is: "This is my website's title which is really long." This title should scroll.

First or initial state should be: "This is my website's title", then it will start scrolling until it shows "itle which is really long."

And then it should not show something like "really long. This is my we" ... but instead, it should go back to the initial state: "This is my website's title".

And as another example, imagine the title is "Website title", now this title shouldn't scroll.

I'm not sure what's the exact amount of visible characters in tabs in different browsers, but I counted in Google Chrome and they are 26.

I'm currently using this code:

(function titleScroller(text) {
        document.title = text;
        console.log(text);
        setTimeout(function () {
            titleScroller(text.substr(1) + text.substr(0, 1));
        }, 500);
    }("This is my website's title which is really long."));

Which I foung in another StackOverflow question, but this one makes the text scroll as I don't want.

Can someone help me to achieve the expected or desired behavior?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire