Showing posts with label Image zoom in and zoom out using Javascript. Show all posts
Showing posts with label Image zoom in and zoom out using Javascript. Show all posts

Thursday, 21 November 2013

Image zoom in and zoom out using Javascript

- Here is the code for simple image zoom in and zoom out using javascript.

Javascript and HTML Code:
---------------------------------------
<html>
<head>
<script language="javascript">
//set the time delay,imgsize,arrsize.
var delay=20;
var imgsize=5;
var timeon;
var wid;
var hei;
var i=0;
function zoom_out(p,q,which)
{
   if(which.width <= p)
      which.width += imgsize;
   if(which.height <= q)
      which.height += imgsize;
   if(which.width <= p)
   {
      var tmp=which.id;
      timeon=eval("setTimeout('zoom_out("+p+","+q+","+tmp+")', delay)");
   }

}

function zoom_in(r,s,asd)
{
 
  if(asd.width >= r)
      asd.width -= imgsize;
  if(asd.height >= s)
      asd.height -= imgsize;

  asd.width=r;
  asd.height=s;
  wid=asd.width;
  hei=asd.height;
}
</script>
</head>
<body>
<table align=center cellspacing=2 cellpadding=2 height=100% width=100%><tr>
<td align=center width=120 height=125 style='cursor:pointer;'>
<img id="myPicture1" src="images/book.gif" width="40" height="48" onMouseover="zoom_out(55,65,this)" onMouseout="zoom_in(40,48,this)"></td>
<td width=10></td>
<td align=center width=120 height=125 style='cursor:pointer;'>
<img id="myPicture2" src="images/globe.gif" width="40" height="48" onMouseover="zoom_out(55,65,this)" onMouseout="zoom_in(40,48,this)"></td>
<td width=10></td>
<td align=center width=120 height=125 style='cursor:pointer;'>
<img id="myPicture3" src="images/email.gif" width="40" height="48" onMouseover="zoom_out(55,65,this)" onMouseout="zoom_in(40,48,this)"></td>
<td width=10></td>
<td align=center width=120 height=125 style='cursor:pointer;'>
<img id="myPicture4" src="images/clock.gif" width="40" height="48" onMouseover="zoom_out(55,65,this)" onMouseout="zoom_in(40,48,this)"></td>
</tr>
<tr><td colspan=7>
</td></tr>
</table>
</body>
</html>

- Don't forget you need 4 images(book,globe,email,clock) in images folder in your local or project.