JavaScript Zoom in and Zoom out

This page discusses - JavaScript Zoom in and Zoom out

JavaScript Zoom in and Zoom out 


This section illustrates you how to zoom in and zoom out of an image using JavaScript.

Here we are providing you an example to show the image effect. For this purpose, we have created three functions. The function zoomImage() and zoom() sets the height and width of the image and make it to show the effect Zoom In and Zoom Out. The function stopZoom() provides the functionality to stop the image effect by using the method clearInterval(). Here we have used Mouseover and Mouseout events to make the image zoom in and zoom out. As long as you put the cursor on the link Zoom In, the size of image will start increasing and if you put the cursor on link Zoom Out., the size of image will start decreasing.

Here is the code:

<h2>Zoom in and Zoom out</h2>
var zoomfactor=0.06;
function zoomImage(){
if (parseInt(>8&&parseInt(>8){*zoomfactor*prefix*zoomfactor*prefix
function zoom(originalWidth, originalHeight, img, state){
prefix=(state=="in")? 1 : -1
if (""||state=="restore"){"px""px"
if (state=="restore")
function stopZoom(){
if (window.beginzoom)
<a href="" onmouseover="zoom(80,100,'image','in')" onmouseout="stopZoom()">Zoom In</a>
<a href="" onmouseover="zoom(100,40,'image','out')" onmouseout="stopZoom()">Zoom Out</a>
<p><img name="image" src="image.jpg"></p>

Zoom Out Effect:

Zoom In Effect:

Download Source Code:



Share on Google+Share on Google+

JavaScript Zoom in and Zoom out

Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: JavaScript Zoom in and Zoom out  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image