View Full Version : [DHTML] EarthQuake II

12-30-2008, 04:49 AM
1) CODE TITLE: EarthQuake II

2) AUTHOR NAME/NOTES: Dynamic Drive - updated by jscheuer1

3) DESCRIPTION: I'm almost ashamed of this one, as it was always annoying. But every so often we get a geologist who wants it, or someone else who thinks it's cute. So I propose that it either be removed from the library or updated (the old script doesn't work in Opera or Chrome, and is quite outdated). This version shakes the page, not the browser, and has some new options (highlighted):

var quakechance = '100%'; //set likelihood an earthquake will occur (100% means always)
var runonload = true; //should earthequake run onload?
var usemessage = true; //should "An earthquake of magnitude . . . " message be used?
var richteroverride = 0; //set to 0 for random richter setting each time (valid values 0 to 10)

It exposes only one global variable and may be called by other scripts if desired.

4) URL TO CODE: http://home.comcast.net/~jscheuer1/side/earthquake_2.htm

12-30-2008, 04:55 AM
That looks nice. I've never liked the earth quake script though, it was just annoying.
Although I do see how your script can act as a protection from bots. You could set it to a high number, so high that humans can't read it, and you can have an input field. And say if you fill in this box with the random number next to it - you're a bot.

12-30-2008, 06:33 AM
That is a great idea @Nile, but on the contrary it can also be used with ajax, if you post an ajax request and the results have been fetched, u can just quake the browser to alert the user....

12-30-2008, 09:34 AM
Does the magnitude actually say how strong the quake was or is it just a random number?

12-30-2008, 03:45 PM
Both actually, unless you set the richteroverride, in which case it isn't random. The 'richterscale' is set to escalate a little less intensely than the real Richter Scale (http://en.wikipedia.org/wiki/Richter_magnitude_scale), the script's is set:

richterscale = [1, 3, 6, 9, 12, 15, 18, 21, 24, 27],

The magnitude is the index of the scale + 1. In some browsers it is harder to differentiate visually between the various magnitudes than it is in others though.

All of this (as regards the scale and magnitude) was already worked out in the original script.