Created
April 21, 2019 01:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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