spacer

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

home / experts / javascript / column32


Positioning A Scroll Box

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

There are many ways to position a scroll box. You can position it in absolute coordinates, but the desired location may change because of an ad put at the top of the page, for example. In this column we use the GIF method. We place a dummy GIF wherever we want in our page:

<IMG SRC="blank.gif"
        NAME="holdspace" ID="holdspace"
        WIDTH="350" HEIGHT="90"
        STYLE="visibility:hidden; position:relative;">

We then compute the coordinates of this GIF in our scrolling box code. We use the IMG's ID to find its object:

var holdingImage = document.images["holdspace"];
var canvasLeft = (NS4) ? holdingImage.x : holdingImage.getRealLeft();
var canvasTop = (NS4) ? holdingImage.y : holdingImage.getRealTop();
var canvasWidth = holdingImage.width;
var canvasHeight = holdingImage.height;

where getRealLeft() and getRealTop() are defined as in Column 13, Scrolling JavaScript Banners:

function getRealLeft() {
	xPos = this.offsetLeft;
	tempEl = this.offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function getRealTop() {
	yPos = this.offsetTop;
	tempEl = this.offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

These functions are needed for Internet Explorer in cases where the IMG tag is positioned inside another container such as a table. See Column 13 for more details on the motivation.

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/position.html