Skip to content

Instantly share code, notes, and snippets.

@brunorafaeI
Created September 4, 2016 12:45
Show Gist options
  • Save brunorafaeI/f27017b767e9d9d9c5350e53b4593613 to your computer and use it in GitHub Desktop.
Save brunorafaeI/f27017b767e9d9d9c5350e53b4593613 to your computer and use it in GitHub Desktop.
Efeito Matrix
<body onload="largura = document.body.scrollWidth;altura = document.body.scrollHeight;">
</body>
function aleatorio(menor,maior){
numPossibilidades = maior-menor;
aleat = Math.random() * numPossibilidades;
aleat = Math.floor(aleat);
return parseInt(menor) + aleat ;
}
var c=0;
texto ="0123456789";
//texto = prompt ("Texto");
var l = texto.split("");
function cria(){
var tfont = aleatorio(10,30);
var left = aleatorio(0,largura-tfont);
for(contp=0;contp<l.length;contp++){
c++;
var top = -contp*tfont;
var n = "c"+c+contp;
var divTag = document.createElement ("div");
if(contp==0){divTag.style.color="#FFF"}
divTag.style.fontSize = tfont+"px";
divTag.style.top=top+"px";
divTag.style.left=left+"px";
divTag.className = "letra";
divTag.id = n;
document.body.appendChild(divTag);
cai(n,top,contp,tfont);
}
}
function cai(nome,top,cx,tfont){
var ct=top;
var tempo = window.setInterval(function(){
document.getElementById(nome).innerHTML = l[cx];
cx++;
if(cx == l.length){
cx=0;
}
document.getElementById(nome).style.top=ct+"px";
ct=ct+tfont;
if(ct>altura-tfont){
clearInterval(tempo);
document.body.removeChild(document.getElementById(nome));
}
}, 100);
}
window.setInterval(function(){cria()},100);
body{background:#000;}
.letra{position:absolute; color:#090; text-align:center;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment