Overlays

Overlay effects load new content over the page based on some action. I, and others, use the term "overlay" because the new content is removed from the page flow completely, being positioned on top of the page through the use of absolute positioning. The overlays can stretch to cover the entire page, or can appear as a small box that is either inserted in or moving across the page.

Yes, these are also known as pop-ups and we're not fond of these. However, the functionality can be used for more than just creating a pop-up (and even a traditional pop-up can be useful if used more to help your web page readers than hide content from them). The overlay that is opened on top of the page can include a warning message, a form to fill in, the results of a query, or even, as demonstrated in this section, a larger size picture when the page reader clicks a thumbnail image.

In my web site, I use an image library to open up a larger image from a smaller thumbnail. It first overlays the page with an element that has an opaque filter so that the page contents don't distract from the picture.

When the page is first loaded, a JavaScript setup function grabs the page contents and wraps them, whatever they are, within a div element. It also adds a second div element containing an img element that is located outside of this wrapper element:

function setUp( ) { // add page container and image container var oldBody = document.body.innerHTML; document.body.innerHTML = "<div id='mtwCover'>" + oldBody ...

Get Adding Ajax now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.