Home arrow HTML arrow Page 3 - Maximizing and Restoring HTML Images: Layer Method
HTML

Maximizing and Restoring HTML Images: Layer Method


If you're writing web pages for an e-commerce web site, you might want to give visitors the ability to enlarge thumbnail images of your products so they can see more detail. You can buy a program that will do this for you -- or you can save your money and read this article to learn how to do it yourself, with a little HTML, JavaScript, and CSS.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
November 04, 2008
TABLE OF CONTENTS:
  1. · Maximizing and Restoring HTML Images: Layer Method
  2. · The Method
  3. · Operation
  4. · Other Image Types

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Maximizing and Restoring HTML Images: Layer Method - Operation
(Page 3 of 4 )

The title attribute of an HTML element is used to produce a tool tip when the mouse pointer is over the element. Our image is given a title attribute, which says, “Click to maximize.” When the image is clicked it is maximized; the tool tip is changed to “Click to Restore.” When you click the maximized image, it is restored; the too tip says “Click to maximize” again.

Unfortunately the tool tip may not show long enough for the user’s satisfaction. So to make sure that the user knows that he can click the image to maximize, on the web page, I have written just below the image, “Quality Watch (Click to maximize).”

Accomplishing it with JavaScript and CSS

I will give you the code before I explain how it works. There is one associated image file with the code. After going through this article, you can try the code.


<html>


<head>


<style type="text/css">

body {z-index:0}

img.watch {width:187px; height:224px}

</style>


<script type="text/javascript">


var maximized = false;


//function to maximize the image.

function maximizeFn()

{

document.getElementById("w1").style.position="absolute";

document.getElementById("w1").style.zIndex="2";

document.getElementById("w1").style.width="374";

document.getElementById("w1").style.height="448";

document.getElementById("w1").style.title="Click to Restore";

maximized = true;

}

 

//function to restore the image.

function restoreFn()

{

document.getElementById("w1").style.position="relative";

document.getElementById("w1").style.zIndex="1";

document.getElementById("w1").style.width="187";

document.getElementById("w1").style.height="224";

document.getElementById("w1").style.title="Click to Maximize";

maximized = false;

}

 

//function to call either the maximizeFn() or restoreFn()

function maxRest()

{

if (maximized == true)

restoreFn();

else

maximizeFn();

}


</script>


</head>


<body>


<table cellpadding="0" cellspacing="0">

<tbody>

<tr>

<td colspan="2" align="center">

<h1>Maximizing and Restoring HTML Image - Layer Method</h1>

</td>

</tr>

<tr>

<td width="100">&nbsp;

</td>

<td width="187" height="224" valign="top">

<img id="w1" src="watch.jpg" class="watch" onclick="maxRest()" title="Click to Maximize" />

</td>

</tr>

<tr>

<td>&nbsp;

</td>

<td><b>Quality Watch</b> (click to maximize)

</td>

</tr>

</tbody>

</table>


</body>


</html>


Explanation of code

An HTML table is used for the layout of the web page. The image element is in a Table Cell. The image has the id, src, class, onclick and title attributes.

For the CSS the body element is given the z-index value of 0. The image is given only the width and height values.

Concerning the JavaScript, when the image is maximized, it is given the absolute position property and a higher z-index value. With this it appears bigger, covering any element it has to cover. There is the global variable “maximized,” which indicates whether the image is maximized or minimized. If the variable is “false,” the function “maximizeFn()” is called. If the value is “true” the function “restoreFn()” is called. The names of the functions and the lines in them are self-explanatory; as you read the lines, bear in mind all that I have said above.


blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials