0

How do I animate site title of site in browser tab like this?

Screen capture GIF:
image description

Cœur
  • 37,241
  • 25
  • 195
  • 267
Obstak
  • 41
  • 1
  • 4
  • Check [this answer](https://stackoverflow.com/questions/23731357/how-do-i-make-text-inside-the-title-tag-animate-using-javascript). – Sam Oct 24 '17 at 23:29

3 Answers3

1

You can add a scroll animation to the title of your browser tab using this Javascript code:

msg = "Title";
msg = " ...Just a scrolling title example" + msg;position = 0;
function scrolltitle() {
document.title = msg.substring(position, msg.length) + msg.substring(0, position); position++;
if (position > msg.length) position = 0
window.setTimeout("scrolltitle()",170);
}
scrolltitle();
0

use window.setTimeout() or window.setInterval() and change document.title

theGleep
  • 1,179
  • 8
  • 14
0

This is pure js...

function recursiveAnimateTitle(string) {
  let firstLetter = string[0];
  let title = document.querySelector('title');
  title.innerHTML += firstLetter;
  if (string.length > 1) {
    setTimeout(function() {
      recursiveAnimateTitle(string.substring(1));
    }, 100);
  }
}

function animateTitle(string) {
  document.querySelector('title').innerHTML = "";
  recursiveAnimateTitle(string);
}

animateTitle('Example Title');
<head>
  <title>Some Default Title</title>
</head>
<body></body>

If you want to vary the time for each letter, use math.random with a range.

With a distribution if you want to get really weird with it.

Amos47
  • 695
  • 6
  • 15