Crazy Windows with JavaScript

Ever seen a browser window shake like crazy? Well here’s a script for it. You can start annoying all your friends with this simple yet crazy script.

This very simple code can shake browser windows, possible driving people crazy. It tends to stop on Internet Explorer (I have not tested it on Internet Explorer 8) if you click on another window, but it works nicely on Firefox and other standard compliant browsers.

<script type="text/javascript">
function lol(){
 self.moveTo(Math.random()*100,Math.random()*100);
 window.setTimeout("lol()",50);
}
window.setTimeout("lol()",50);
</script>

This code first defines a function called lol() which contains the self object connected to the moveTo() function. The notation is:

moveTo([distance from left],[distance from top])

The example above generates a random string which is between 0 and 1(like 0.5487732…) using the random() function of the Math object and multiplies it by 500 to make a number that’ll move the window enough.

We then have the setTimeout() function. The notation of this one is:

setTimeout("[function]“,[time(in milliseconds)])

So, in this case, the position of the window changes every 50 milliseconds. You can adjust this to make it faster or slower.

Have fun!

Preview the example (press alt+f4 to close)

April 20, 2009 in Tutorials
Tagged , ,

Leave a Reply

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>