| home / experts / dhtml / column3 |
|

Since we know that you enjoyed zooming the little red buttons on the previous page, we have captured all clicks on this page as well. You know the routine:
<A NAME="imBigGuy">
<IMG
NAME="imZJup" SRC="jupiter.jpeg" WIDTH=80 HEIGHT=60 HSPACE=20 ALIGN=LEFT></A>
<A HREF="/3d/lesson17/">
<IMG
NAME="imZFruit" SRC="3d.jpg" WIDTH=80 HEIGHT=60 HSPACE=20 ALIGN=LEFT BORDER=0></A>
<A HREF="/outlook/column5/">
<IMG
NAME="imRich" SRC="richWig.gif" WIDTH=80 HEIGHT=60 HSPACE=20 BORDER=0></A>
You may have noticed that the one image that did not zoom in Navigator on the previous page was the one that was not a link. Although the documentation states that the click should be captured in the whole document, it seems to be captured only in links and margins. To avoid making things difficult, we can use the mousedown event.
In the Netscape scheme of things, all objects are not exposed to script manipulation. Not yet, anyway. Nor does the event object identify its source element. We therefore have to perform two workarounds:
Before we consider a way to expand the image's dimensions, we have to identify an image as the recipient of a click event. We use the pageX and pageY properties of the event object. (event.x and event.y in IE)
Once we know where on the page the click occurred, we try to assign these coordinates to an image by going through the document.images array and checking against the position of each displayed image. It's a roundabout, but it's the only way.
First, let's modify findIt to work with both browsers.
IMPORTANT
All the work is done in the getImage function:
In our for loop, we access four image properties to determine the four page coordinates that define its rectangle: x, y, width, and height. We have not seen x or y documented anywhere, but they exist as read-only properties.
By determining if the mouse click occurred within the boundaries of an image, we are in a position to tell findIt how to proceed. Our return value does that. If this value (gotIt) is true, findIt calls zoomOutInEl.
Since we cannot expand our image in-line with Netscape, we will do so off-line. That is, in an absolutely positioned CSS element that will pop up and contain the zoomed image.
That means we have to backtrack for a minute to create our element, which we will call, are you ready for this, elZoom.
No CSS element exists by its declaration alone. It must be also be inserted into the HTML flow. Since our element, unlike those in our previous column, will not be immediately visible and we don't even know where it will popup, we define it at the end of our document. We will create it dynamically in a <SCRIPT> placed just before the </BODY> tag. This will also help our code to be completely backward compatible and appendable.
Notice, of course, that our element is completely empty. We will write the HTML to it later. In our declaration, we positioned elZoom at 0,0 to avoid having it drawn at the end because, since it's invisible, Netscape would render its height in blank space at the end of the page.
Function zoomOutInEl looks like this:
After getting our new width and height, we create a string of HTML that we will write to the CSS element. The IMG tag contains many quotes so be careful to escape the quotes belonging to the tag. Compare the above scripted tag to the HTML tag (with fake values added):
Since every element has a document object, we use the document.write method.
IMPORTANT
Using the new JavaScript 1.2 method moveTo, we position the element over our image to be zoomed. All that is left is to make it visible and set our zoomed variable.
Now, this is easier than Explorer. We simply make the CSS element hidden, revealing the original image underneath it. Modify the zoomIn function:
Now that we have covered the basics, let's modify our routine so we can zoom only selected images.
Produced by Peter Belesis and
All Rights Reserved. Legal Notices.
Created: 08/27/97
Revised: 09/28/97
URL: http://www.webreference.com/dhtml/column3/allPicsNS.html