JavaScript
  Home arrow JavaScript arrow Page 3 - Building Image Zooming Controls with the D...
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

Building Image Zooming Controls with the DOM for JavaScript
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-03-25

    Table of Contents:
  • Building Image Zooming Controls with the DOM for JavaScript
  • The previous version of the image zooming application
  • Building zoom controls by using some DOM scripting
  • Source code for the 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


    Building Image Zooming Controls with the DOM for JavaScript - Building zoom controls by using some DOM scripting


    (Page 3 of 4 )

    According to the concepts deployed in the previous section, it's necessary to define yet another JavaScript function that will be responsible for building the pair of zoom controls that were initially included into the zooming application's structural markup. From a strict point of view, this approach is much more standard and allows this application to degrade gracefully if scripting is disabled on the browser.

    Having explained why it's better to build the respective zoom controls, this is the signature of the function that appends them dynamically to the web document tree:


    function buildZoomPanel(){

    var div=document.createElement('div');

    div.setAttribute('id','controlpanel');

    var btnplus=document.createElement('input');

    btnplus.setAttribute('type','button');

    btnplus.setAttribute('value','+');

    var btnminus=document.createElement('input');

    btnminus.setAttribute('type','button');

    btnminus.setAttribute('value','-');

    div.appendChild(btnplus);

    div.appendChild(btnminus);

    document.getElementsByTagName('body')[0].appendChild(div);

    btnplus.onclick=function(){ZoomInElement('image',20,800)};

    btnminus.onclick=function(){ZoomOutElement('image',20,263)};

    }


    As you can see, the above "buildZoomPanel()" JavaScript function performs some useful tasks, such as creating the zoom buttons that are added to the web page by using some common DOM methods. Also, after these buttons are built, they are tied via two "onclick" event handlers to the respective "ZoomInElement()" and "ZoomOutElement()" functions that you learned before.

    And finally, the previous function should be called up in the following way after the web page has been loaded:


    // display zoom panel when web page is loaded

    window.onload=function(){

    if(document.getElementById&&document.getElementsByTagName&&document.createTextNode){

    buildZoomPanel();

    }

    }


    Not too difficult to grasp, right? At this point, the zooming application has been improved in many different ways, since it now has the capacity to perform a pretty realistic zooming effect on any number of bitmapped images. It also builds the corresponding zoom panel by using the DOM.

    Of course, if you want to work with multiple images, you should slightly modify the signature of the previous "buildZoomPanel()" function to create one panel for each of the targeted graphics. This should be a no-brainer task that you can tackle with minor hassles.

    So far, so good. At this stage, you hopefully learned how the prior "buildZoomPanel()" function works, so it's time to see how it can be linked with the other modules of this image zooming application. This will complete its development.

    As you may guess, this integration process will be tackled in the section to come, thus click on the link that appears below and keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


       · This last part of the series completes the development of this JavaScript-driven...
     

    JAVASCRIPT ARTICLES

    - 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
    - Active Client Pages at the Server
    - ACP Tab Web Page







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