Home arrow JavaScript arrow Page 3 - Building Image Zooming Controls with the DOM for JavaScript
JAVASCRIPT

Building Image Zooming Controls with the DOM for JavaScript


Welcome to the final part of the series entitled “Zooming images with JavaScript.” In four different tutorials, this series demonstrates how to use some of the most common methods provided by JavaScript to build a highly modular client-side application that allows for decent zooming effects on multiple images in a web document.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
March 25, 2008
TABLE OF CONTENTS:
  1. · Building Image Zooming Controls with the DOM for JavaScript
  2. · The previous version of the image zooming application
  3. · Building zoom controls by using some DOM scripting
  4. · Source code for the image zooming application

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

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