JavaScript
  Home arrow JavaScript arrow Page 3 - Working with Multiple Graphics for a Zoom ...
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? 
JAVASCRIPT

Working with Multiple Graphics for a Zoom Application in JavaScript
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-03-18

    Table of Contents:
  • Working with Multiple Graphics for a Zoom Application in JavaScript
  • Listing the source code of the previous zooming application
  • Zooming into and out of multiple images
  • Completing the improved image zooming application

  • 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


    Working with Multiple Graphics for a Zoom Application in JavaScript - Zooming into and out of multiple images


    (Page 3 of 4 )

    In the previous section of this tutorial, I pointed out that the current incarnation of this image zooming application had some important limitations, such as the inability to work with multiple bit-mapped graphics. Indeed, this issue can be easily addressed by introducing some modifications to the business logic implemented through its respective behavioral layer (the JavaScript code, in other words).

    Below I defined two brand new JavaScript functions, which, when used in conjunction, implement an effective mechanism for zooming different graphics included in a given web page.

    Please study the respective signatures corresponding to the aforementioned functions, which look like this:


    // zoom in a selected web page element

    function ZoomInElement(id,inc,maxWidth){

     var elem=document.getElementById(id);

     if(!elem||elem.getAttribute('width')>=maxWidth){return};

    elem.setAttribute('width',parseInt(elem.getAttribute('width'))+inc);

    elem.setAttribute('height',parseInt(elem.getAttribute('height'))+inc);

    if(!elem.style.left){elem.style.left='0px'};

    if(!elem.style.top){elem.style.top='0px'};

    elem.style.left=parseInt(elem.style.left)-(inc/2)+'px';

    elem.style.top=parseInt(elem.style.top)-(inc/2)+'px';

    }


    // zoom out a selected web page element

    function ZoomOutElement(id,inc,minWidth){

     var elem=document.getElementById(id);

     if(!elem||elem.getAttribute('width')<=minWidth){return};

    elem.setAttribute('width',parseInt(elem.getAttribute('width'))-inc);

    elem.setAttribute('height',parseInt(elem.getAttribute('height'))-inc);

    if(!elem.style.left){elem.style.left='0px'};

    if(!elem.style.top){elem.style.top='0px'};

    elem.style.left=parseInt(elem.style.left)+(inc/2)+'px';

    elem.style.top=parseInt(elem.style.top)+(inc/2)+'px';

    }


    After studying the definitions of the above JavaScript functions, you'll have to agree with me that they're  quite easily grasped. As you can see, the functions in question accept  the ID of the image being zoomed into and out of as its respective input argument along with the pertinent incremental and decremental values that will be applied to the image's width and height attributes.

    And finally, both functions also take up the minimum and maximum values that should be assigned to the mentioned attributes so the zooming effect can be applied within a predefined range. Pretty easy to follow, isn't it?

    All right, at this point I've built a brand new pair of JavaScript functions, which not only have been provided with the capacity to zoom any image included in a web document, but with the ability to perform this visual effect within a predefined range of increment and decrement values.

    Now that you've hopefully learned how the two previous JavaScript functions do their thing, I believe that it's time to see how the functions can be linked with the rest of the modules that comprise this image zooming application.

    Want to find out how this integration process will be achieved? Great! All you have to do is to click on the link shown below and read the next few lines.

    More JavaScript Articles
    More By Alejandro Gervasio


       · Over the course of this third chapter of the series, the functionality of the...
     

    JAVASCRIPT ARTICLES

    - Comparing Fields and Customizing Error Messa...
    - Checking Numbers and File Extensions with jQ...
    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek