Availability: |
| ||||
JavaScript syntax: | N | myLayer = myDocument.aLayerName | |||
N | myLayer = myLayerArray[anIndex] | ||||
HTML syntax: | <ILAYER>, <LAYER> | ||||
Argument list: | anIndex | An index into the layer array | |||
Object properties: | above, background, below, bgColor, clip, document, hidden, left, name, pageX, pageY, parentLayer, siblingAbove, siblingBelow, src, top, visibility, window, x, y, zIndex | ||||
Object methods: | load(), moveAbove(), moveBelow(), moveBy(), moveTo(), moveToAbsolute(), offset(), resizeBy(), resizeTo() | ||||
Functions: | captureEvents(), handleEvent(), releaseEvents(), routeEvent() | ||||
Event handlers: | onBlur, onFocus, onLoad, onMouseOut, onMouseOver, onMouseUp | ||||
Collections: | layers[] |
Each layer in Netscape is somewhat like a separate window or frame. This means it has its own document associated with it which can itself also contain layers. The individual objects cannot be positioned themselves but the layers they live in can be.
The Netscape Layer object has many properties that are similar to the MSIE Style object. However although they bear some similarities, they also have many differences. Furthermore a layer is not a style and therefore it is difficult to conveniently map one to the other and build cross-platform solutions without constructing a compatibility layer.
Note that Netscape prior to version 6.0 instantiates an absolutely positioned <DIV> container as a Layer object.
Event handling support via properties containing function objects was added to Layer objects at version 1.1 of JavaScript.
The example demonstrates how to control a scrolling panel and do it in a way that is cross browser compliant for MSIE and Netscape version 4. There are a lot of issues to deal with, not least the fact that Netscape supports layers but MSIE does not. It is necessary to use layers for scrolling in Netscape because you can only scroll windows or frames in Netscape if they have visible and active scrollbars. Also, the two browsers scroll vertically in opposing directions. If you are careful about the sizing of your objects, and relate the size of the window/frame the layer is drawn in, you can accomplish a continuous scrolling effect by duplicating items from the top of the list to the bottom. Then at an appropriate point, you can jump scroll back to the top of the list. If you do this right, it will appear as if the list is endless and scrolling gently in a continuous loop. This technique is a much simplified example taken from the Video On Demand console at http://www.bbc.co.uk/news where there is a panel showing a listing of live TV programs in a scrolling pane.
If you are using layers to position items temporarily on the screen, then you should be careful when using absolute positioning. This can cause the layer to be absolutely positioned relative to the current mouse position and not the window border. The effect is that an item in the positioned layer will appear to follow the mouse as it is clicked. You may need to work out the mouse position and then calculate an offset to relocate the layer where you want it. You may be able to detect the mouse by removing focus from the layer that has the problem, or it may be necessary to create an empty layer which can be safely attached to the mouse. All of these issues are Netscape 4 specific.
Layers are no longer supported in Netscape 6.0.
<HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> // Initialize globals var theScrollValue = 0; var theMaxScroll = 50; // Work out what kind of browser we are on function getBrowserType() { var myUserAgent; var myMajor; myUserAgent = navigator.userAgent.toLowerCase(); myMajor = parseInt(navigator.appVersion); if( (myUserAgent.indexOf('mozilla') != -1) && (myUserAgent.indexOf('spoofer') == -1) && (myUserAgent.indexOf('compatible') == -1) && (myUserAgent.indexOf('opera') == -1) && (myUserAgent.indexOf('webtv') == -1) ) { if (myMajor > 3) { return "nav4"; } return "nav"; } if (myUserAgent.indexOf("msie") != -1) { if (myMajor > 3) { return "ie4"; } return "ie"; } return "other"; } // Start the correct scroller for this browser function startScroller() { eval(getBrowserType() + "_scrollPage()"); } // Browser specific scroller (IE) function ie4_scrollPage() { self.scrollTo(0,theScrollValue); theScrollValue++; if(theScrollValue == theMaxScroll) { theScrollValue = 0; } setTimeout("ie4_scrollPage()", 100); } // Browser specific scroller (Navigator) function nav4_scrollPage() { self.document.layer1.moveTo(0,-theScrollValue); theScrollValue++; if(theScrollValue == theMaxScroll) { theScrollValue = 0; } setTimeout("nav4_scrollPage()", 20); } </SCRIPT> </HEAD> <BODY ONLOAD="startScroller();"> <LAYER TOP=0 LEFT=0 NAME="layer1"> <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0> <TR HEIGHT=25><TD VALIGN=TOP>Headline 1<BR></TD></TR> <TR HEIGHT=25><TD VALIGN=TOP>Headline 2<BR></TD></TR> <TR HEIGHT=25><TD VALIGN=TOP>Headline 3<BR></TD></TR> <TR HEIGHT=25><TD VALIGN=TOP>Headline 4<BR></TD></TR> <TR HEIGHT=25><TD VALIGN=TOP>Headline 5<BR></TD></TR> <TR HEIGHT=25><TD VALIGN=TOP>Headline 6<BR></TD></TR> </TABLE> </LAYER> </BODY></HTML>
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
above | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
background | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
below | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
bgColor | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
clip | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
document | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
hidden | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
left | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
name | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
pageX | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
pageY | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
parentLayer | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
siblingAbove | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
siblingBelow | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
src | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
top | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
visibility | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
window | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
x | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
y | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
zIndex | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Method | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
load() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
moveAbove() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
moveBelow() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
moveBy() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
moveTo() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
moveToAbsolute() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
offset() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
resizeBy() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
resizeTo() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Event name | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
onBlur | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
onFocus | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
onLoad | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
onMouseOut | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
onMouseOver | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
onMouseUp | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Prev | Home | Next |
Language codes | Up | Layer() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |