Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make text inside the title tag animate using JavaScript?

How do I show a scrolling (moving) message in the title?

 <title>Welcome to Some title</title>

Translate the titlebar into a dynamic that displays additional information using JavaScript (without any CSS).

like image 923
raghul Avatar asked May 19 '14 06:05

raghul


1 Answers

Here's an eye catching example to get your visitors back when your web page tab is not active within the browser (onblur). This script will animate the original title text with an intro, the original title text is restored when the tab is returned to active state (focus). When the tab is clicked the original page title is restored. For social media sharing it is highly recommended to include the original page title text with the prefaced animated text (onblur).

$(function() {

var origTitle, animatedTitle, timer;

function animateTitle(newTitle) {
  var currentState = false;
  origTitle = document.title;  // save original title
  animatedTitle = "Hey There! " + origTitle;
  timer = setInterval(startAnimation, 2000);

  function startAnimation() {
    // animate between the original and the new title
    document.title = currentState ? origTitle : animatedTitle;
    currentState = !currentState;
  }
}

function restoreTitle() {
  clearInterval(timer);
  document.title = origTitle; // restore original title
}

// Change page title on blur
$(window).blur(function() {
    animateTitle();
});

// Change page title back on focus
$(window).focus(function() {
    restoreTitle();
});

});
like image 87
Monica Bohanon Avatar answered Oct 14 '22 10:10

Monica Bohanon