spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / gr / column7 / 1 To page 1To page 2current page
[previous]

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


How to Create a JavaScript Web Page Screen Saver

So, how do you fit the screen saver code into a web page? By instantiating a ScreenSaver object and passing it a suitable settings object:

<html>
  <head>
    <script src="JSGraphics.js"></script>
<script src="ScreenSaver.js"></script>
<script src="StarFieldSaver.js"></script>
<script type="text/javascript">
var saver;
function initScreenSaver()
{
      saver = new ScreenSaver(
      {  
        timeout:5000,
speed:50,
nStars:100,
zIndex:100,
create:function(){return new StarFieldSaver(this);}
        }
      );
    }
</script>
  </head>
<body onload="initScreenSaver();">
    <h1>A Typical Web Page</h1>
<p>...</p>
<div id=debug></div>
  </body>
</html>

For readers unfamiliar with object literals, the call to instantiate a new ScreenSaver might seem a little strange, but it’s valid JavaScript. The new ScreenSaver function is passed one object, defined by the curly braces. Inside this object are four properties; timeout, speed, nStars and zIndex. There is also a function (and as far as the object is concerned, this is also a property), which will be used by the ScreenSaver to create the flavor of screen saver desired.

Conclusion

In this article, I’ve created a JavaScript framework that integrates a screen saver into a web page. The screen saver code was divided into two sections: one to control the starting and stopping, and one for the screen saving part that hides the page contents and shows an animation.

To see a working demonstration of this code, click here.

A Little Disclaimer

While I’ve done my best to make this code browser compatible (meaning that it’s been tested with Internet Explorer 6.0 and Netscape 7.1, which accounts for over 80% of users), it won’t work for everyone. To appease the small but appreciable set of users who have disabled JavaScript, this code will fail gracefully and leave the web page alone.

About the Author

Guyon Roche is a freelance web developer in London, Great Britain. He specializes in Windows platforms with an interest in bridging the gaps between different technologies, visit www.silver-daggers.co.uk for more details. He can be reached via e-mail at guyonroche@silver-daggers.co.uk


home / programming / javascript / gr / column7 / 1 To page 1To page 2current page
[previous]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

Created: March 27, 2003
Revised: June 8, 2004

URL: http://webreference.com/programming/javascript/gr/column7/1