spacer

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

home / experts / javascript / column32


Setting Up the Viewing Area

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

The scroll box is set up inside the makeCanvas() function. In Internet Explorer, it starts with extracting the HTML code from the external file into firstPage and secondPage

function fillAllPages() {
  var text = '<DIV ID="canvas" STYLE="position:absolute">';
  text += '<DIV ID="firstPage" STYLE="position:absolute">'
   + arBody[0].innerHTML + '</DIV>';
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
  text += '<DIV ID="secondPage" STYLE="position:absolute">'
   + arBody[0].innerHTML + '</DIV>';
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
  text += '</DIV>';
  document.body.insertAdjacentHTML("BeforeEnd", text);
}

Notice the hierarchical structure of these dynamic HTML elements. The canvas element contains the firstPage and secondPage elements.

In Netscape Navigator, the canvas element is created via a layer constructor:

canvas = new Layer(canvasWidth);

The clipping area of the canvas is generated next. While in Netscape Navigator the creation of a clipping area is as simple as property assignment, you need to use the rect() constructor in Internet Explorer:

if (IE4){
  canvas.style.clip = "rect(0 " + canvasWidth + " " + canvasHeight + " 0)";
}
else {
  canvas.clip.width = canvasWidth;
  canvas.clip.height= canvasHeight;
}

The remainder of the makeCanvas() function sets the width, height, top, left, background color, and visibility properties of the scrolling box:

eval("canvas" + styleString).width = canvasWidth;
eval("canvas" + styleString).height = canvasHeight;
if (NS4) {
  canvas.left = canvasLeft;
  canvas.top = canvasTop;
  canvas.bgColor = GcanvasColor;
}
else {
  canvas.style.pixelLeft = canvasLeft;
  canvas.style.pixelTop = canvasTop;
  canvas.style.backgroundColor = GcanvasColor;
}
eval("canvas" + styleString).visibility = (NS4) ? "show" : "visible";

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Created: December 21, 1998
Revised: December 21, 1998

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