Home arrow HTML arrow Page 4 - 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 - Other Image Types
(Page 4 of 4 )

I have used a JPEG image just to avoid an unnecessary debugging problem; this is to ensure that the code I have given in this article will work, if you try it. You can use any type of image accepted by browsers in your other projects.

Image Resolution

You might have noticed in the past that when you increase the size (dimensions) of an image from the original size taken from the scanner, its resolution (fineness) is lost. However, when you reduce the size (dimensions) of an image its resolution is not lost.

The solution is this: let the original size taken from your scanner (or digital camera) be the largest size that you can have on your web page. Let this be the size that will be downloaded onto you web page. What we call the normal size of the main image above will simply be a result of the values we force for the image in the style sheet properties. The maximized size should not be greater than the actual size obtained from the scanner.

Side Effect

When the image is maximized, its position may change a bit (vertically downwards). This is a side effect, but it is not very bad, since the maximized image will cover elements anyway. Also, the user clicks the image when he wants to maximize the image. When the image is maximized, he concentrates on the image. The slight change in position is therefore not too important.

However, there is a possible solution for this.

Solution to Side-Effect

Browsers today do not handle the CSS “position:absolute” property as they should. So any solution you can get is based on experience with different browsers. Our maximized image is in a Table Cell. Giving the Table Cell the attribute and value ‘valign="top"’ would solve the problem.

Testing

Copy the code into a text editor. Save the file with the name “max_rest.htm” in a directory. Save the image file in the same directory. Open the HTML file in your browser. Click the image; it maximizes, covering anything (text) it has to cover in order to maximize. Click the maximized image, and the image should be restored.

Summary:

  • The image to be maximized is given the CSS “position:absolute” property.

  • The image to be maximized should not be given the CSS Left and Right properties.

  • The image to be maximized is given a z-index that is higher than those of its surrounding elements.

  • The dimensions of the image are increased to maximize it.

  • The vertical align property of the parent element, preferably the TD element, should be given a value of “top.”

  • To restore, reverse the third and fourth points above. You may also give the image the CSS “position:relative” property.

Conclusion

If you are developing web pages for e-commerce, shopping or some other purpose, you can write code to increase or decrease the size of images. You do not need to know how to develop a particular type of image (eg. JPEG). The code you write is not long. You use JavaScript and CSS to do this. With this little effort, you save money.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials