Home arrow JavaScript arrow Page 2 - Zooming in on Images with JavaScript
JAVASCRIPT

Zooming in on Images with JavaScript


Assuming that zooming-in bitmapped images with JavaScript may be interesting and useful to you, in this series of tutorials, I’ll develop a highly-expansible client side application, which will be tasked with enlarging (and decreasing when applicable) the dimensions of a specific image.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
March 04, 2008
TABLE OF CONTENTS:
  1. · Zooming in on Images with JavaScript
  2. · Developing a basic front-end
  3. · Defining a couple of handy JavaScript functions
  4. · Attaching the JavaScript functions to the zooming controls

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Zooming in on Images with JavaScript - Developing a basic front-end
(Page 2 of 4 )

As I stated in the introduction of this tutorial, the first step that I’m going to take toward the development of a JavaScript application that will be capable of zooming in and out a concrete bitmapped image will consist of building a simple front-end. This will be handy for placing the image that will be manipulated later into the respective web page.

Now have a look at the signature of the following (X)HTML file, which displays two simple containing DIVs on the browser. As you’ll see, the first one will be responsible for housing the sample image that will be zoomed in and out via JavaScript. The second one will include a pair of web form buttons for implementing a primitive control panel.

The corresponding code sample is as follows:


<!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</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>

</head>

<body>

<h1>Zooming images with JavaScript</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 you can see, the signature corresponding to the above (X)HTML file is indeed very easy to grasp. As I stated before, this file includes two main DIVs. The first one, which is identified as “container,” wraps the sample image to be zoomed in and out, and the last one acts merely like a containing element for the controls that will perform the pertinent zooming process on the target image. Not too difficult to understand, right?

In addition, I styled this pair of containing DIVs, which results in a web document that has the following visual presentation:



As illustrated by the previous screen shot, the front-end that corresponds with the zooming JavaScript application is very primitive, so you shouldn’t have major problems understanding how it works.

So far, so good. At this moment everything has been set up correctly. It’s time to leap forward and start coding the respective JavaScript functions that will be tasked with zooming in and out of the previous sample image via the respective zoom controls. Things are getting really exciting now!

However, to see how these brand new JavaScript functions will be created, you’ll have to 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 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials