Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
Created April 21, 2019 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazy4groovy/e18b5739da9e218f344a48e54e46db03 to your computer and use it in GitHub Desktop.
Save crazy4groovy/e18b5739da9e218f344a48e54e46db03 to your computer and use it in GitHub Desktop.
Scroll a message across the browser tab's Title and/or URL hash
function scrollMessage(message, timeoutMs, changeTitle, changeUrl) {
if (!message || !(changeTitle || changeUrl)) return function stopScroll() {}
if (changeTitle) document.title = message
if (changeUrl) document.location.hash = message
function init() {
var index = 0
function scrollerTick() {
index = (index + 1) % message.length
var scrolledMessage = message.substr(index) + message.substring(0, index)
if (changeTitle) document.title = scrolledMessage
if (changeUrl) document.location.hash = scrolledMessage
}
return setInterval(scrollerTick, Number(timeoutMs) || 500)
}
var clearId = init()
return function stopScroll() { clearInterval(clearId) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment