HTML
  Home arrow HTML arrow Page 3 - Maximizing and Restoring HTML Images with ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

Maximizing and Restoring HTML Images with the Image Map Method
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-16

    Table of Contents:
  • Maximizing and Restoring HTML Images with the Image Map Method
  • The Method
  • Image Map
  • Testing and Finalizing

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Maximizing and Restoring HTML Images with the Image Map Method - Image Map


    (Page 3 of 4 )

    I assume you already know how to create an image map. We shall call the clickable area "clickMaxRes" (meaning, click to maximize or restore). With simple calculation you can figure out that the start of a clickable area of 16 X 16 pixels, at the bottom right end of the normal sized image, will begin at approximately 171px, 208px of the image. It will end at the bottom right end of the main image, which is approximately 187px, 224px. With this in mind, replace the image code in the body element of the HTML file with the following:


    <img id="w1" src="watch.jpg" usemap ="#clickMaxRest" class="watch" />

    <map id ="clickMaxRest" name="clickMaxRest">

    <area id = "a1" shape ="rect" coords ="171,208,187,224" onclick="maximizeRestore()" title="Maximize" />

    </map>


    The usemap attribute has been given the value #clickMaxRest, so the ID for the map tag has been given the value clickMaxRest. Its name attribute has been given the same value, clickMaxRest, for backward compatibility with older browsers. The area tag has been given the ID a1 (we shall see its function shortly). As indicated above, the start x and y coordinates for the clickable area are (171px, 208px). The end x and y coordinates are (187px, 224px), which are the bottom right end coordinates. Would it not be nice for a tool tip to display the text "Maximize" when the mouse pointer is over the clickable maximization area? This is why the area tag ends with title="Maximize".

    When the triangle is clicked, a JavaScript function will be called. This is the only function in the JavaScript. It will be called maximizeRestore(). That is why you have onclick="maximizeRestore()" for the onclick event in the area tag above. A code block in this function will increase the dimensions of the image using the style sheet. It will also give the image new image-map coordinates, where the clickable area will be at the bottom right end of the enlarged (maximized) image. The maximized image is twice the size of the normal-sized image, so the area containing the triangle will be approximately 32px X 32px.

    When the triangle is clicked at the maximized size, the same JavaScript function will be called. Another code block in this function will decrease the dimensions of the image back to its normal size using the style sheet. It will also give the image the old image-map coordinates. Type the following JavaScript in the head element of the HTML file below the style sheet:


    <script type="text/javascript">


    //flag to indicate whether the image is maximized or restored

    var restored = true; 

     

    //function to maximize or restore the main image.

    function maximizeRestore()

    {

    if (restored == true)

    {//block to maximize the image.

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

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

    document.getElementById("a1").coords="342,416,374,448";

    document.getElementById("a1").title="Restore";

    restored = false;

    }

    else

    {//block to restore the image.

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

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

    document.getElementById("a1").coords="171,208,187,224";

    document.getElementById("a1").title="Maximize";

    restored = true;

    }

    }


    </script>


    There is a variable in the script called "restored." Its value at the start of the script is Boolean TRUE. This is a flag that indicates whether the image is restored or maximized. When the web page is loaded, the image is initially at the restored size, so the value is initially TRUE. If you click the triangle, the JavaScript function maximizeRestore() will be called. This is the only function in the script. Since the Restored variable is true, the first code block will be executed. The first line in this code increases the width of the image. The second line in the code increases the height of the image. The third line sets the new clickable area of the image. The fourth line gives the new clickable area the title "Restored," so that if the user's mouse pointer is over it, the word "Restored" will appear to indicate that clicking the area will restore the image. Since the image is now maximized, the fifth line sets the Restored flag to False.

    If you click the triangle while the image is maximized,, the JavaScript function will be called. Since the Restored flag has been set to False, the second code block of the function will be executed. The first line of this block decreases the width of the image. The second line in the code decreases the height of the image. The third line sets the former clickable area of the image back. The fourth line gives the former clickable area its former title, "Maximize," so that if the user's mouse pointer is over it, the word "Maximize" will appear to indicate that clicking the area will maximize the image. Since the image is now restored, the fifth line sets the Restored flag to True, as it was before.

    More HTML Articles
    More By Chrysanthus Forcha


       · You do not really need a special software in order to have an image that can be...
     

    HTML ARTICLES

    - Comparing Browser Response to Active Client ...
    - Testing Browser Response to Active Client Pa...
    - Active Client Pages: Completing the Code for...
    - ACP and Browsers: Setting up an Example
    - How Browsers Respond to Active Client Pages
    - Completing a Tree with Active Client Pages
    - HTML Form Verification and ACP
    - Building an ACP Tree
    - Completing an ACP 3D HTML Table Image Gallery
    - Building an ACP 3D HTML Table Image Gallery
    - A Multiple Page Image Gallery with Active Cl...
    - Building an Image Gallery with Active Client...
    - Concluding a Menu for All Browsers
    - A Vertical Menu for All Browsers
    - Downloading Long HTML Pages with ACP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT