Home arrow JavaScript arrow Page 3 - Working with Multiple Graphics for a Zoom Application in JavaScript
JAVASCRIPT

Working with Multiple Graphics for a Zoom Application in JavaScript


Welcome to the third installment of the series "Zooming out images with JavaScript." This set of educational tutorials guide you through the process of developing a highly modular JavaScript application that has the capacity to perform basic zoom in/out effects on a certain number of bit-mapped images previously included in a web document.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
March 18, 2008
TABLE OF CONTENTS:
  1. · Working with Multiple Graphics for a Zoom Application in JavaScript
  2. · Listing the source code of the previous zooming application
  3. · Zooming into and out of multiple images
  4. · Completing the improved image zooming application

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.


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