Code solutions to PHP, JS, CSSCode source PHP, JS, CSS

Spread your code soluces to the world

Love me
Solucior » JAVASCRIPT » Javascript Image magnification

Javascript Image magnification

06/16/2011 by Dux   -   4.5/5 (10 ratings)

Add magnifying glass options on your images with this simple code.


image zoom loupe

source code

<script type="text/javascript">
zoom(e, sens) {
elm = document.getElementById(e);
// Image width
var w = (elm.offsetWidth) ? elm.offsetWidth :;
// Parent element width
var wc = (elm.parentNode.offsetWidth) ? elm.parentNode.offsetWidth :;
// Image size
w = (sens>0) ? w * 1.25 : w / 1.25;
   if (
w < wc) w = wc; = w + "px";

<div style="width: 400px; height: 303px; overflow: scroll; border: 1px solid">
   <img id="nice" src="nice.jpg" alt="image zoom loupe" style="width:100%" />
<input type="button" value="-" onclick="zoom('nice', -1)" />
<input type="button" value="+" onclick="zoom('nice', 1)" />

Tested with Safari  Google Chrome  Firefox3  Firefox4  Opera  IE6  
Rate this code     |     Copied : 94x

Comments for Javascript Image magnification

No comment
Add a comment Nickname   Site

Javascript Image magnification
Isolate a color
Extract images from a page
Horizontal scroll div with javascript
Dynamic image resizing according to location
Javascript opacity
Adjust the rate of image colors
Zoom with CSS3
Simple image gallery PHP
Automatically adjust brightness contrast of an image