Skip to content

Instantly share code, notes, and snippets.

@AnderssonPeter
Last active August 6, 2019 09:10
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 AnderssonPeter/a74ec570a32b5c71ebce6882d03bc0f5 to your computer and use it in GitHub Desktop.
Save AnderssonPeter/a74ec570a32b5c71ebce6882d03bc0f5 to your computer and use it in GitHub Desktop.
Javascript jokes
const fadeText = function () {
function getRandomColor () {
return '#'+Math.floor(Math.random()*16777215).toString(16);
}
const words = 'You shall not debug I am a servant of the JavaScript wielder of the flame of V8. You cannot Debug. The dark fire will not avail you flame of Google. Go back to the IE! You cannot pass.'.split(' ');
var div = document.createElement('div');
div.setAttribute('style', 'position: fixed; right: 10px; bottom: 10px;z-index: 100000; font-size: 100px; font-weight: bold;');
document.body.appendChild(div);
function fade(initial, step, delay, callback) {
div.style.display = 'block';
var op = initial; // initial opacity
var timer = setInterval(function () {
div.style.opacity = op;
div.style.filter = 'alpha(opacity=' + op * 100 + ")";
op += step;
if (op <= 0){
clearInterval(timer);
div.style.display = 'none';
callback();
}
else if (op >= 1) {
clearInterval(timer);
callback();
}
}, delay);
}
div.style.opacity = 0;
function fadeInNextWord() {
if (words.length > 0) {
div.style.position = 'fixed';
div.style.left = (Math.random() * 50) + '%';
div.style.top = (Math.random() * 50) + '%';
div.innerText = words.shift();
div.style.color = getRandomColor();
fade(0, 0.2, 75, fadeOut);
}
}
function fadeOut() {
fade(1, -0.2, 75, fadeInNextWord);
}
fadeInNextWord();
return div;
}
var counter = 0;
var callback = function (event) {
counter++;
if (counter == 10) {
document.removeEventListener('click', callback);
fadeText();
}
}
document.addEventListener('click', callback, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment