<%@ Page Language="C#" Debug="true"%> Code Samples
Microsoft Office FrontPage 2003      
Developer's Toolkit
Resources | Links | Search
  extend design code  
             
  New Features
 
Microsoft® Windows® SharePoint Services
 
Microsoft® Office SharePoint Portal Server
 
Microsoft Office System
 
.NET Framework
 
 
Real world scenarios that fully expose great new functionality in FrontPage 2003 and Windows SharePoint Services.
 
 
  financial planning finance  
  sales & marketing sales & marketing  
  human resources human resources  
   
  FrontPage Customization Kit > Resources > Code Library

Graphical Countdown Timer Documentation

Contents

Examples page

Download this sample

 

Summary

The Countdown Timer enhances a countdown timer with words or graphics. There are three types of countdown timers. The first displays a countdown in a combination of numbers and words. The second displays either a horizontal bar which changes color as the countdown nears zero. The third displays one of a series of graphics, selected based on how near to zero the countdown has reached.

The Countdown Timer is created in javascript with the CountdownTimer object. The most important methods to use are one of the render methods: RenderText, RenderHorizontalBar or RenderImage. Additionally, for the horizontal bar or image countdown timers, you will use one of the Add... methods to add phases where the color or image is supposed to change. Finally, use the StartAutoRefresh method to update the countdown timer and keep it updated.

Both types of countdown timers (the horizontal bar and the image) share the ability to countdown using one of two methods. The first countdown method indicates the percentage of progress from a fixed beginning point in time to a fixed end point in time. The second countdown method indicates the time remaining for a countdown that begins when the countdown is started, which could be the moment the page is loaded, or any point afterwards.
 

 

Usage

There is one required file: countdown.js. Include it on your page with a line like this:

	<script type="text/javascript" src="countdown.js"></script>

Then, to use the CountdownTimer object, you will need another script block on your page to create an instance of the CountdownTimer, like this:

	<script type="text/javascript">
		var Countdown = new CountdownTimer();
	</script>

Once you have created the CountdownTimer, you will need to render countdown timers wherever you want in your HTML source.

The text timer is rendered with the RenderText method. Simply call this method wherever you want the countdown text placed in your document, like this:

	<script type="text/javascript">
		dtStart = new Date("9/1/2003");
		dtStop = new Date("1/1/2004");
		Countdown.RenderText
                  ("timerTextNewYear", dtStart, dtStop, "");
	</script>

The horizontal bar CountdownTimer does not position itself or control its size. To do this, you need to enclose the call to the RenderHorizontalBar method inside an HTML element that establishes the size of the bar. Additionally, if you plan to have a thin bar, you will need to limit the size of the horizontal bar with the overflow attribute. To display a horizontal bar countdown timer within a DIV element, use the RenderHorizontalBar method, like this:

	<div id="bar" style="position: relative; 
           width: 100%; height: 12px; overflow: hidden; ">
		<script type="text/javascript">
		dtStart = new Date("9/1/2003");
		dtStop = new Date("1/1/2004");
		Countdown.RenderHorizontalBar
            ("timerBar", dtStart, dtStop, "black", "silver");
		</script>
	</div>

The string "timerBar" is used to provide the unique ID for the HTML element that will be inserted into the page. It is also the ID you will use to add the details of the times that the horizontal bar will change its appearance. It is up to you to decide how to initialize the start and stop times. The example here starts the countdown on an arbitrary date and stops it at the end of the year. The string "black" is used for the foreground color of the countdown, and the string "silver" is used as the background color.

If you would rather display a series of images which change over time, use the RenderImage method instead, like this:

	<script type="text/javascript">
		dtNow = new Date();
		dtTenSeconds = dtNow.valueOf() + 10000; // 10000 ms = 
                   ten seconds
		Countdown.RenderImage
                 ("timerImage", dtNow, dtTenSeconds, 
                  "countdown1.gif", 126, 126);
	</script>

The string "timerImage" is used to provide the unique ID for the HTML element that will be inserted into the page. It is also the ID you will use to add the details of the times that the image will change its appearance. It is up to you to decide how to initialize the start and stop times. The example here starts the countdown when the page is loaded, and stop it ten seconds later. The string "countdown1.gif" is the initial image displayed, and the values 126 and 126 are the width and height, respectively, of the image.

Next, you will provide the details of the times where the countdown timer should change its appearance. You have two ways to do this. The first way is to provide specific dates and times when the timer will change. The second way is to provide the percentage between the start time and the end time when the timer will change. The first way looks like this:

	<script type="text/javascript">
		Countdown.AddColorChangeTime 
             ("timerBar", new Date("10/1/2003"), "blue", "silver");
		Countdown.AddColorChangeTime 
             ("timerBar", new Date("11/1/2003"), "green", "silver");
		Countdown.AddColorChangeTime 
               ("timerBar", new Date("12/1/2003"), "yellow", "silver");
		Countdown.AddColorChangeTime 
               ("timerBar", new Date("1/1/2004"), "red", "silver");
	</script>

Note that the last date listed here is the stop date of our previous example. In this example, this has the effect of making the horizontal bar remain red after the stop date has passed. You do not need to repeatedly call the AddColorChangeTime method in any particular order; the CountdownTimer will change based on the times provided.

The second way to provide the times when the timer should change its appearance is by percentage. The previous example, rewritten to use percentages instead of specific times, looks like this:

	<script type="text/javascript">
		Countdown.AddColorChangePercent  
             ("timerBar", 100, "red", "silver");
		Countdown.AddColorChangePercent 
             ("timerBar", 25, "blue", "silver");
		Countdown.AddColorChangePercent 
             ("timerBar", 75, "yellow", "silver");
		Countdown.AddColorChangePercent 
             ("timerBar", 50, "green", "silver");
	</script>

The numbers 100, 25, 75, and 50 are the percentages (100%, 25%, 75%, and 50%) between the start time and the end time which were provided when you created the horizontal bar countdown timer.

Finally, call the StartAutoRefresh method to begin having the CountdownTimer update all of the elements that you have rendered on the page, like this:

	<script type="text/javascript">
		Countdown.StartAutoRefresh(500);
	</script>

This begins updating all of the elements on the page every 500 milliseconds (every 0.5 seconds).
 

 

Reference

There is only one object for this feature. The CountdownTimer object provides all of the functionality required.

CountdownTimer object
Properties

There are no public properties for this object.

Methods
Method Parameter Description
AddColorChangePercent   Adds a point in time when a horizontal bar countdown timer will change its foreground and background colors, based on a percentage between the start and stop times for a specific horizontal bar countdown timer.
sCountdownID String that specifies the ID of the horizontal bar countdown timer that was used when the timer was rendered.
nPercent Integer that specifies the percentage, expressed as a whole number between 0 and 100, inclusive. When the time elapsed between the start and stop times passes this percentage, the provided foreground and background colors will be used.
rgbFore String that specifies the color for the left-most color that will progress towards the right side. Acceptable values include any standard color value.
rgbBack String that specifies the color for the right-most color that is replaced by the left-most color. Acceptable values include any standard color value.
AddColorChangeTime   Adds a point in time when a horizontal bar countdown timer will change its foreground and background colors, based on a fixed point in time between the start and stop times for a specific horizontal bar countdown timer.
sCountdownID String that specifies the ID of the horizontal bar countdown timer that was used when the timer was rendered.
dtmPoint Date object that specifies the fixed point in time. When the time elapsed between the start and stop times passes this point in time, the provided foreground and background colors will be used.
rgbFore String that specifies the color for the left-most color that will progress towards the right side. Acceptable values include any standard color value.
rgbBack String that specifies the color for the right-most color that is replaced by the left-most color. Acceptable values include any standard color value.
AddImageChangePercent   Adds a point in time when an image countdown timer will change its image, based on a percentage between the start and stop times for a specific image countdown timer.
sCountdownID String that specifies the ID of the image countdown timer that was used when the timer was rendered.
nPercent Integer that specifies the percentage, expressed as a whole number between 0 and 100, inclusive. When the time elapsed between the start and stop times passes this percentage, the provided image will be used.
sImageURL String that specifies the URL to the image to use. You can specify a document-relative, root-relative, or absolute URL.
AddImageChangeTime   Adds a point in time when an image countdown timer will change its image, based on a fixed point in time between the start and stop times for a specific image countdown timer.
sCountdownID String that specifies the ID of the image countdown timer that was used when the timer was rendered.
dtmPoint Date object that specifies the fixed point in time. When the time elapsed between the start and stop times passes this point in time, the provided image will be used.
sImageURL String that specifies the URL to the image to use. You can specify a document-relative, root-relative, or absolute URL.
RenderHorizontalBar   Draws the horizontal bar countdown timer inside a parent HTML element on the page.
sCountdownID String that specifies a unique ID for the element that contains the horizontal bar countdown timer. Refer to this ID when calling Add...Change... methods.
dtmStart Date object that specifies the absolute date and time when the countdown starts.
dtmStop Date object that specifies the absolute date and time when the countdown ends.
rgbFore String that specifies the color for the left-most color that will progress towards the right side. Acceptable values include any standard color value.
rgbBack String that specifies the color for the right-most color that is replaced by the left-most color. Acceptable values include any standard color value.
RenderImage   Draws the image countdown timer on the page.
sCountdownID String that specifies a unique ID for the element that contains the horizontal bar countdown timer. Refer to this ID when calling Add...Change... methods.
dtmStart Date object that specifies the absolute date and time when the countdown starts.
dtmStop Date object that specifies the absolute date and time when the countdown ends.
sDefaultImageURL String that specifies the URL to the image to use. You can specify a document-relative, root-relative, or absolute URL. You may use any image type accepted by browsers.
cx Integer that specifies the width of the image in pixels.
cy Integer that specifies the height of the image in pixels.
StartAutoRefresh   Begins an interval timer which periodically checks all of the countdown timers on a page to see which ones need to change their appearance, and updates them.
nInterval Integer that specifies the length of the interval in milliseconds.
StopAutoRefresh   Halts the interval timer, effectively freezing all of the countdown timers on the page.
 


Remarks

The horizontal bar countdown timer does not have any positioning properties or methods. If you do not enclose it within another element, it expands to fill the entire page. To control the size of the horizontal bar, be sure to include the call to the RenderHorizontalBar method inside an enclosing HTML element with the position and size of the horizontal bar that you want, as illustrated in the example.
 

 

Customization

This section contains suggestions for how you can customize the script to suit your particular needs. The script provided does not already contain the necessary code to implement these suggestions. The suggestions merely provide guidance on how you might apply your own customizations.

Vertical countdown timer

The function CountdownTimer_RenderHorizontalBar, in countdown.js, creates two DIV elements, one positioned within the other. The outer DIV is used for the background color. The inner DIV is used for the foreground color. The foreground DIV is positioned to be the full height of the outer DIV. To change this to a vertical bar countdown timer, set the width of the inner DIV to 100%, and the height to 0px.

The function CountdownTimer_RefreshBar is the function which draws the horizontal countdown timer. The last line of this function sets the width of the element which displays the foreground color. Change this line to set the height of the foreground color instead.

Notification of changes

It may be useful to know when a countdown timer has reached a point in time when it changes its appearance. To do this, study the function CountdownTimer_OnRefresh(). This line:

	if (nChange != elmTimer.timerCurrentChange)

is a test to determine whether the countdown timer has passed a point in time when its appearance should change. If the test is true, then the countdown timer should change its appearance. Although this function currently applies this test only to image countdown timers, it can also be used for horizontal bar countdown timers, as long as it is placed after the call to CountdownTimer_RefreshBar(), which moves the foreground color along the horizontal bar.


^ Back to top