The Overlay control is an extension of Module; its role is to facilitate the creation of modular content that is absolutely positioned above the flow of a page. It adds additional functionality to Module, including methods for positioning, multiple custom events for monitoring internal property changes, and a built-in IFRAME solution for dealing with SELECT element bleed-through in Internet Explorer.
Overlay is fundamentally a building block for other UI controls. The concepts presented in this example will form the basis for the way that you interact with all of its subclasses.
In this tutorial we will build three Overlays with different types of positioning. One of them will be based on existing markup; the other two will be created dynamically using script. In addition to instantiating the Overlays, we will also use the constructor to pass configuration properties for each of our Overlays.
These Overlays introduce a few configuration properties. The "fixedcenter" property, when set to true, will force the Overlay to always be positioned in the center of the viewport — even when the window is scrolled or resized. The "visible" property determines whether the Overlay should be visible, and the "width" property allows a CSS width to be set for the Overlay. In addition, basic pixel-based positioning is available via the "xy" property, which can also be split into separate properties ("x" and "y").
The "context" property, as shown in "overlay3", takes an array of arguments. The first argument in the array is the id of the element to which we want to anchor the Overlay. In this case, that element is a div with an id of "ctx". The next two arguments specify the positioning of the Overlay — "tl" and "bl" mean, "Anchor my Overlay's top left corner to my context element's bottom left corner." (Other possible values include "tr" and "br" for "top right" and "bottom right", respectively.)
In the next step, we will define CSS styles that allow us to see a clear visual representation of our Overlays; remember, Overlays are building blocks for other controls and as such they are not styled by default. We will also style our "ctx" context element so that it's easy to see:
The markup for "overlay1", plus the context element "ctx" and the buttons to show all our Overlays, is displayed below. Note that "overlay1" has an inline style of "visibility:hidden" set in advance. Most browsers are slower to render CSS than inline styles, and we want this marked-up Overlay to be hidden by default. If the inline style isn't present, it may cause a brief "flash of unstyled content" where the Overlay may be visible on slower machines.