VIRUS ATTACK!
This script simulates a virus attack (of the type experienced in the early days of viruses) on a page by slowly wiping out all the words on a page until there are none left. It is not running on this page for obvious reasons! See it in action using my
F.A.Q. page
.
This script has been tested on and shown to work with Internet Explorer 5+, Netscape 6+, Firefox 1.0 and Opera 7+
27-Apr-2005
: First release.
STEP 1:
Copy and paste the code below so that it sits between the <head> and </head> tags at the top of your web-page:
<script type="text/javascript"> // <![CDATA[ var delay=5; // seconds until attack starts var seconds=60; // seconds until attack complete (from start) /***************************\ * Mock-Virus Text Effect * * (c) 2005 mf2fm web-design * * http://www.mf2fm.com/rv * * DON'T EDIT BELOW THIS BOX * \***************************/ var colours=new Array("#090", "#0f0", "#6f6", "#cfc", "transparent"); var elems=new Array(); var chars=new Array(); var elmax=chmax=0; window.onload=function() { if (document.getElementById) { var i, j, txt, parent, span, words; getAllText(document.body); for (i=0; i<elmax; i++) { txt=elems[i].nodeValue; parent=elems[i].parentNode; words=elems[i].nodeValue.split(" "); for (j=0; j<words.length; j++) { span=document.createElement("span"); span.appendChild(document.createTextNode(words[j])); parent.insertBefore(span, elems[i]); if (j!=words.length-1) parent.insertBefore(document.createTextNode(" "), elems[i]); chars[chmax++]=span; } parent.removeChild(elems[i]); } virus(); }} function virus() { var i, t, j; for (i=0; i<chmax; i++) { t=1000*(delay+seconds*Math.random()); for (j=0; j<colours.length; j++) setTimeout('chars['+i+'].style.backgroundColor="'+colours[j]+'"', t+100*j); setTimeout('chars['+i+'].style.visibility="hidden"', t+100*j); } setTimeout('document.body.style.cursor="pointer";document.body.onclick=function(){top.location.href="http://www.mf2fm.com/rv/"};end()', 1000*(delay+seconds)); } function end() { document.body.style.backgroundColor=colours[elmax=++elmax%colours.length]; setTimeout("end()", 100); } function getAllText(el) { if (el.nodeType==3 && !el.nodeValue.match(/^\s+$/)) elems[elmax++]=el; if (!el.childNodes.length) return; else for (var i=0; i<el.childNodes.length; i++) getAllText(el.childNodes[i]); } // ]]> </script>
CLICK HERE
to select the above script ready to paste it into your clipboard
THAT'S IT
When your page loads, it should look like it is under attack by a virus (though of course it isn't really!)
No menu on the left?
Click here
for a full list of all the free DHTML and Javascript effects you could be using on your web-site!
Interested in learning more about JavaScript, CSS, HTML/XHTML/XML and PHP programming? I would highly recommend the following books...
[ This page viewed 3119 times. Last viewed Sun 20 Jul, 2008 at 05:33 ]