CVI
shiftzoom.js 1.9 allows you to add zoom and pan functionality to oversized images on your webpages. It uses unobtrusive javascript to keep your code clean.

It works in all the major browsers - Mozilla Firefox 1.5+, Opera 9+, IE 6+ and Safari. Works also on older browsers supporting images/ createElement/ getElementById, else it'll degrade and your visitors won't notice a thing.

Demonstration


Click to see what shiftzoom.js can do.
caribbean
Caribbean (simple)
monalisa
Mona Lisa (frame)
mosaic
Mosaic (multiple)

Images used are copyrighted and are used for demonstration only.

Setting Up

Download shiftzoom.js and include it into your webpages HEAD section.

<script type="text/javascript" src="shiftzoom.js"></script>

// only if the cursor images for IE are not in the current path
<scriptscript type="text/javascript">
  shiftzoom.defaultCurpath='images/cursors/';
</script>

Using It

To add shiftzoom just set the event onload="shiftzoom.add(this);" to an div surrounded image.

<div><img onLoad="shiftzoom.add(this);" width="400" height="200" ...></div>

Mouse- and Keyboard-driven handling:

shiftleft mouse  zoom in    mouse wheel  zoom in    middle mouse  zoom in* 
altleft mouse  zoom out    mouse wheel  zoom out    right mouse  zoom out* 
* must be set through preferences by Firefox and Opera (gecko/presto)

Keyboard-driven handling: (if focused through mouse over image)

left  pan left    shiftleft  pan left (fast)    altleft  pan left (slow) 
right  pan right    shiftright  pan right (fast)    altright  pan right (slow) 
up  pan up    shiftup  pan up (fast)    altup  pan up (slow) 
down  pan down    shiftdown  pan down (fast)    altdown  pan down (slow) 
plus  zoom in*    end  zoom in (fast)    pgdn  zoom in 
minus  zoom out*    home  zoom out (fast)    pgup  zoom out 
* not supported by Firefox and Opera (gecko/presto)

Usage

Set defaults
shiftzoom.defaultFading     = true; //BOOLEAN startup image fading
shiftzoom.defaultButtons    = true; //BOOLEAN left top buttons
shiftzoom.defaultZoom       = 0; //INT/FLOAT 0-100 (%) zooming percentage
shiftzoom.defaultXpos       = 50; //INT/FLOAT 0-100 (%) horizontal position
shiftzoom.defaultYpos       = 50; //INT/FLOAT 0-100 (%) vertical position
shiftzoom.defaultOpacity    = 70; //INT 0-100 (%) zoom button opacity
shiftzoom.defaultMillisec   = 30; //INT 5-100 zoom interval delay
shiftzoom.defaultIntitle    = 'zoom in'; //STR zoom in button title text
shiftzoom.defaultOuttitle   = 'zoom out'; //STR zoom out button title text
shiftzoom.defaultCurpath    = ''; //STR cursor path (*.cur) IE only
shiftzoom.defaultShowcoords = false; //BOOLEAN show coordinates
shiftzoom.defaultPixelcoords= true; //BOOLEAN show pixel coords instead of Lat/Lon
shiftzoom.defaultOverview   = true; //BOOLEAN show overview
shiftzoom.defaultOvsfact    = 25; //INT 10-50 (%) overview size factor
shiftzoom.defaultOvaopac    = 75; //INT 0-100 (%) overview area opacity
shiftzoom.defaultOvacolor   = 'red'; //STR overview area css color
shiftzoom.defaultOvbcolor   = 'white'; //STR overview border css color
shiftzoom.defaultOvborder   = ''; //INT 0-20 (px) or "" overview border width

Add functionality to image
shiftzoom.add(image[, options]);
image  == div surrounded image
options         e.g. {overview: true, opacity: 32, ...}
fading     == BOOLEAN true or false Default: true
buttons    == BOOLEAN true or false Default: true
zoom       == INT/FLOAT 0 - 100 Default: 0
xpos       == INT/FLOAT 0 - 100 Default: 50
ypos       == INT/FLOAT 0 - 100 Default: 50
opacity    == INT 0 - 100 Default: 90
millisec   == INT 5 - 100 Default: 40
intitle    == STRING Default: 'click or press shift key to zoom in'
outtitle   == STRING Default: 'click or press alt key to zoom out'
curpath    == STRING Default: ''
showcoords == BOOLEAN true or false Default: false
pixelcoords== BOOLEAN true or false Default: true
overview   == BOOLEAN true or false Default: true
ovsfact    == INT 10 - 50 Default: 25
ovaopac    == INT 0 - 100 Default: 75
ovacolor   == STRING '#ffaa00' or 'orange' Default: 'red'
ovbcolor   == STRING '#0000ff' or 'blue' Default: 'white'
ovborder   == INT 0 - 20 Default: automatic

Get some informations
FLOAT|INT = shiftzoom.get(image, ['maxzoomx'|'maxzoomy'|'maxwidth'|'maxheight']);

Modify some defaults
shiftzoom.set(image, ['buttons'|'overview'|'showcoords'|'pixelcoords'], [true|false]);

Modify current source image
shiftzoom.source(image, value, boolean);
value == URI (e.g. 'images/world.jpg')
boolean == fade out/in (true or false)

Modify current zooming
shiftzoom.zooming(image, value);
value == 0 - 100 (%) default: 0

Modify current position
shiftzoom.moveto(image, x, y);
x,y default: 0,0
if x or y == INT e.g. 189
then it's interpreted as pixel from within natural image dimension

if x or y == STR e.g. '50%' Pattern: (INT|FLOAT)%
then it's interpreted as percentage

if x or y == STR e.g. '-23.057' Pattern: (+|-)(INT|FLOAT)
then it's interpreted as longitude or latitude

Remove functionality from image
shiftzoom.remove(image);

Examples
<img onLoad="shiftzoom.add(this);" ...>
shiftzoom.add(document.getElementById('img'));
if(typeof $=='undefined') {function $(v) {return(document.getElementById(v));}}
shiftzoom.add($('img'));
shiftzoom.add($('img'), {fading:false, curpath:'cursors/'});
shiftzoom.set($('img'),'overview',false);
alert(shiftzoom.get($('img'),'maxwidth'));
shiftzoom.source($('img'),'images/world.jpg',false);
shiftzoom.zooming($('img'),100);
shiftzoom.moveto($('img'),'50%','50%');
shiftzoom.remove($('img'));

Why use Javascript shiftzoom?

In very old browsers, the script degrades and your visitors won't notice a thing.

Download

Please read the License before you download shiftzoom.js 1.9

F.A.Q.

Please read the Frequently Asked Questions before you contact the author.

Restrictions

Operas cursor handling sucks. IE needs external cursor images (*.cur).

Handling javascript mouse events is not a simple thing, because there are inconsistancies in the way different browsers implement mouse events. That's the reason why the response on right mouse button is inconsistent in shiftzoom. The differences in detail:

History

Version 1.9

Version 1.8 Version 1.7 Version 1.6 Version 1.5 Version 1.4 Version 1.3 Version 1.2 Version 1.1 Version 1.0

Contact

Please leave any comments at this contact formular.

License

shiftzoom.js is distributed under the Netzgestade Non-commercial Software License Agreement.
License permits free of charge use on non-commercial and private web sites only under special conditions (as described in the license). This license equals neither "open source" nor "public domain". There are also Commercial Software Licenses available.

YOU AGREE TO ALL CONDITIONS OF THIS LICENCE AGREEMENT CONCERNING THE USE OF THE SOFTWARE BY ACCEPTING THIS LICENCE.
IF YOU DO NOT AGREE TO ALL CONDITIONS OF THIS AGREEMENT, YOU SHALL NOT INSTALL THE SOFTWARE, OR USE IT IN OTHER WAYS.