spacer

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

home / experts / dhtml / diner / resize
DHTML Diner Logo

This is a Netscape Navigator 4 technique. The in-page examples will only work in Navigator 4 versions with the bug (ex. v4.04).

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Ensuring DHTML Layout on Resize (3)

Recall that the syntax for handling the resize event is:

   function resizeHandler() {
      ...statements to execute on a resize...
   }

   window.onresize = resizeHandler;

To work around the bug, we must alter the syntax to:

   function resizeHandler() {
      ...if a true resize event occured, then...
      ...statements to execute on a resize...
   }

   window.onresize = resizeHandler;

We must, therefore, ensure that the resize event is a real one, instigated by a user resizing of the browser window, before any function statements are executed. To do this, we must verify if the size of the window has changed! We'll need to compare the size of the window before and after the event.

Early in our page, we create two variables, origWidth and origHeight to store the original width and height of the browser window:

origWidth = innerWidth;
origHeight = innerHeight;

Then we simply compare the value of these variables to the window width and height after a resize. If either dimension is different, it means a true resize has occured, and we can execute our statements. We also re-declare the origWidth/origHeight variables to store the new resized window dimensions, to use when the next resize occurs.

   function resizeHandler() {
      if (innerWidth != origWidth
          || innerHeight != origHeight) {
               origWidth = innerWidth;
               origHeight = innerHeight;
               ...statements to execute on a resize...
      }
   }

   window.onresize = resizeHandler;

Alternately, the function can look like this, returning if a match is found, and doing nothing:

   function resizeHandler() {
      if (innerWidth == origWidth
          && innerHeight == origHeight) return
               origWidth = innerWidth;
               origHeight = innerHeight;
               ...statements to execute on a resize...
   }

   window.onresize = resizeHandler;

Whichever syntax you use, your handler function will execute its statements only if a true resize has occured, avoiding the bug.

On the final page, we'll use what we have learned to create a simple bug-proof handler for the resize event that will ensure our DHTML layout remains intact.



Produced by Peter Belesis and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

All Rights Reserved. Legal Notices.
Created: May 07, 1998
Revised: Oct 07, 1998

URL: http://www.webreference.com/dhtml/diner/resize/resize3.html