spacer

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

home / experts / javascript / column32


Sliding the Pages

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

The scrolling of the pages is triggered by the scrollPages() function, which is called from within the launchScroller() function, and is also the event handler for the mouseout event. Here is the scrollPages() function:

function scrollPages() {
  Gtimer = setInterval("moveUp()", Ginterval)
}

This function executes the moveUp() function every Ginterval milliseconds. The Gtimer variable is a pointer to the setInterval() event, and is important for stopping the scrolling, as explained later in this column.

The moveUp() function is the one that actually moves the layers up. Moving things in Internet Explorer is much different than in Netscape Navigator. In Explorer we move DIVs by changing the pixelTop property:

upperPage.style.pixelTop -= Gincrement;
lowerPage.style.pixelTop -= Gincrement;

while in Netscape we use the moveBy() method:

firstPage.moveBy(0,-Gincrement);
secondPage.moveBy(0,-Gincrement);

The pages need to be rotated when the lower page's top coordinate becomes negative. In Internet Explorer, the pixelTop property is examined:

if (lowerPage.style.pixelTop <= 0)

and in Netscape Navigator, the top property is examined.

The rotation is accomplished by adding twice the height of the page to the coordinate of the upper page. In Internet Explorer:

upperPage.style.pixelTop += upperPage.clientHeight*2;

and in Netscape Navigator:

upperPage.moveBy(0,upperPage.clip.height*2);

Here is the whole function:

function moveUp() {
  if (NS4) {
    firstPage.moveBy(0,-Gincrement);
    secondPage.moveBy(0,-Gincrement);
    if (lowerPage.top <= 0){ upperPage.moveBy(0,upperPage.clip.height*2);
           rotateThePages();
         }
  }
  else {
    upperPage.style.pixelTop -= Gincrement;
    lowerPage.style.pixelTop -= Gincrement;
    if (lowerPage.style.pixelTop <= 0) {      
      upperPage.style.pixelTop += upperPage.clientHeight*2;
      rotateThePages();
    }
  }
}

The function rotateThePages() is fully consistent between the two browsers. It exchanges the roles of the first page and the second page:

function rotateThePages() {
  if (upperPage == firstPage) {
    upperPage = secondPage;
    lowerPage = firstPage;
    return true;
  }
  upperPage = firstPage;
  lowerPage = secondPage;
  return true;
}

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

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: December 21, 1998
Revised: December 21, 1998

URL: http://www.webreference.com/js/column32/move.html