JavaScript
  Home arrow JavaScript arrow Page 2 - Working with Multiple Graphics for a Zoom ...
IBM Rational Software Development Conference
CIO Insight
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  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 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 / 1
    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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Working with Multiple Graphics for a Zoom Application in JavaScript - Listing the source code of the previous zooming application
    (Page 2 of 4 )

    A good way to demonstrate how the initial zooming application can be considerably improved to provide it with the capacity to work with more than one bit-mapped image involves listing its complete source code as it was developed in the preceding article of the series. In doing so, you'll be able to compare this version of the application with the one that I plan to build later on. Sounds pretty logical, right?

    Having said that, have a look at the signature of the following (X)HTML file, which implements a fully-functional zooming effect on a predefined image:


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Zooming images with JavaScript (uses only one function)</title>

    <style type="text/css">

    body{

    padding: 0;

    margin: 0;

    background: #eee;

    }

    h1{

    font: bold 14pt Arial, Helvetica, sans-serif;

    color: #000;

    text-align: center;

    }

    img{

    position: absolute;

    }

    #container{

    position: relative;

    width: 263px;

    height: 150px;

    margin-left: auto;

    margin-right: auto;

    overflow: hidden;

    background: #9cf;

    border: 1px solid #000;

    }

    #controlpanel{

    width: 263px;

    margin-left: auto;

    margin-right: auto;

    background: #9cf;

    text-align: center;

    border: 1px solid #000;

    }

    </style>

    <script type="text/javascript">

    function ZoomImage(inc){

    var img=document.getElementById('image');

    if(!img){return};

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

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

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

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

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

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

    }

    window.onload=function(){

    var btn1=document.getElementById('button1');

    if(!btn1){return};

    btn1.onclick=function(){

    ZoomImage(20);

    }

    var btn2=document.getElementById('button2');

    if(!btn2){return};

    btn2.onclick=function(){

    ZoomImage(-20);

    }

    }

    </script>

    </head>

    <body>

    <h1>Zooming images with JavaScript (uses only one function)</h1>

    <div id="container"><img src="sample_image.jpg" width="263" height="150" id="image" /></div>

    <div id="controlpanel">

    <p><input type="button" id="button1" value="+" /><input type="button" id="button2" value="-" /></p>

    </div>

    </body>

    </html>


    As shown earlier, the above code sample implements an extensible JavaScript application that performs a zooming in/out effect on a selected image. Of course, this task is carried out by the respective "ZoomImage()" function, which was actually discussed in detail in the previous tutorial, so I won't bore you with explaining how it works again.

    So far, so good. At this stage you hopefully recall how the prior zooming application does its thing, even when it lacks the capacity to work with multiple images. Therefore, I think that it's time to introduce some crucial modifications to the pertinent JavaScript code to make it zoom in/out more than one graphic.

    To see how this will be achieved, please click on the link below and keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


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

    JAVASCRIPT ARTICLES

    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps
    - Adding Zoom Controls to Yahoo! Maps
    - Working with Yahoo! Maps
    - Building Image Zooming Controls with the DOM...
    - Working with Multiple Graphics for a Zoom Ap...
    - Improving an Image Zooming Application with ...
    - Zooming in on Images with JavaScript
    - JavaScript Date Objects: Universal Coordinat...
    - Javascript Objects: More Date Methods
    - JavaScript Objects: Dates
    - JavaScript Objects: Finishing Strings

    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway