Javascript File (in js folder) | Description |
jquery-1.10.0.min.js | jQuery source - http://jquery.com/ |
jquery.hammer.min.js | handles touch events - http://eightmedia.github.io/hammer.js/ |
jquery.mousewheel.min | handles mousewheel events - https://github.com/brandonaaron/jquery-mousewheel |
modernizr.min.js | handles feature detection - http://modernizr.com/ |
TweenMax.min.js | handles animation - http://www.greensock.com/ |
jquery.pinchzoomer.min.js | main script |
CSS File (in css folder) | Description |
pinchzoomer.min.css | main CSS file that defines zoom buttons |
Image File (in assets folder) | Description |
preloader.gif | default preloader image |
zoom_in.png | default zoom in image |
zoom_out.png | default zoom out image |
<link href="css/touchnswipe.min.css" rel="stylesheet"> <script src="js/jquery-1.10.0.min.js" type="text/javascript"></script> <script src="js/jquery.mousewheel.min.js"></script> <script src="js/jquery.hammer.min.js" type="text/javascript"></script> <script src="js/modernizr.min.js" type="text/javascript"></script> <script src="js/TweenMax.min.js" type="text/javascript"></script> <script src="js/jquery.pinchzoomer.min.js" type="text/javascript"></script>
<img id="img1" src="assets/1.jpg" />jQuery
$("#img1").pinchzoomer();That's it. By adding $("#img1").pinchzoomer(); in your JS code, you just added multi-touch zoom to your image. Below is what it looks like
var pzVars = { imageOptions:{}, //set your image options inside the {} like { scaleMode:"heightOnly", maxZoom:6 } controlOptions:{}, //set the control options inside the {} like { alwaysShow:true } zoomInOnStyle:"", //set the class name when zoom in is enabled zoomInOffStyle:"", //set the class name when zoom in is disabled zoomOutOnStyle:"", //set the class name when zoom out is enabled zoomOutOffStyle:"" //set the class name when zoom out is disabled }; $("#img1").pinchzoomer(pzVars); //inititalize plugin to process image with the id of "img1"
Option | Default Value | Description |
adjustHeight | 0 | the accepted value is any number. This determines how much height (in pixels) you want to add or remove to your image. |
adjustWidth | 0 | the accepted value is any number. This determines how much width (in pixels) you want to add or remove to your image. |
animDuration | 0.3 | the accepted value is any positive number. This determines how long (in seconds) is the animation. |
doubleTapZoom | 2 | the accepted value is any positive number. This value is the scale when the image is double tapped or double clicked. |
ease | Power4.easeOut | the accepted value is any easing function. This determines the easing function of the animation. |
maxZoom | 5 | the accepted value is any positive number more than 1.This determines the maximum zoom of the image. |
preloaderUrl | assets/preloader.gif | the accepted value is an image filename. This determines the image used as a preloader. |
resizeDuration | -1 | the accepted value is -1 or any positive number. This determines how long in seconds before checking if the size of the gallery is changed. Note: Use this if you constantly change the size of your gallery or if your gallery is not resizing. |
scaleMode | widthOnly | the accepted value is widthOnly, heightOnly, proportionalInside, full and none. This determines the initial width and height of the image. For more info check out the next section below. |
zoomStep | 0.5 | the accepted value is any positive number. This determines how much scale you want to add or remove in the image when zoom control buttons are pressed. |
var pzVars = { imageOptions:{ preloaderUrl:"assets/preloader2.gif", maxZoom:6 } }; $("#img1").pinchzoomer(pzVars);
<img id="img1" src="assets/chairs.jpg" data-elem="pinchzoomer"/>Javascript and jQuery
var pzVars = { imageOptions:{ scaleMode:"widthOnly" } }; $("#img1").pinchzoomer(pzVars);
.zoomInOn, .zoomInOff, .zoomOutOn, .zoomOutOff { width:86px; height:22px; display:block; position:absolute; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .zoomInOn, .zoomInOff { background-image:url(../assets/custom_zoom_in.png); bottom:10px; left:50%; } .zoomOutOn, .zoomOutOff { background-image:url(../assets/custom_zoom_out.png); bottom:10px; right:50%; } .zoomInOn, .zoomOutOn { opacity:1; cursor:pointer; } .zoomInOff, .zoomOutOff { opacity:0.3; cursor:auto; }
//using default CSS $("#img1").pinchzoomer(); //using custom CSS var pzVars2 = { zoomInOnStyle:"customZoomInOn", zoomInOffStyle:"customZoomInOff", zoomOutOnStyle:"customZoomOutOn", zoomOutOffStyle:"customZoomOutOff" }; $("#img2").pinchzoomer(pzVars2);
.customZoomInOn, .customZoomInOff, .customZoomOutOn, .customZoomOutOff { width:86px; height:22px; display:block; position:absolute; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .customZoomInOn, .customZoomInOff { background-image:url(../assets/custom_zoom_in.png); bottom:10px; left:50%; } .customZoomOutOn, .customZoomOutOff { background-image:url(../assets/custom_zoom_out.png); bottom:10px; right:50%; } .customZoomInOn, .customZoomOutOn { opacity:1; cursor:pointer; } .customZoomInOff, .customZoomOutOff { opacity:0.3; cursor:auto; }
Option | Default Value | Description |
alwaysShow | false | the accepted value is true or false. If true, it will always display the zoom controls. If false, the zoom controls will only show when the mouse is over the image or when the image is tapped. |
var pzVars = { controlOptions:{ alwaysShow:true } }; $("#img1").pinchzoomer(pzVars);
Public property | Description |
image | contains the generated image by PinchZoomer. image here is a jQuery object. |
vars | contains the PinchZoomer options like minZoom, maxZoom, preloaderUrl, etc. |
Public method | Description |
zoomIn () | Adds to the scale of the image defined by "zoomStep" option |
zoomOut () | Subtracts to the scale of the image defined by "zoomStep" option |
zoom (value, duration) | value parameter sets the scale factor of the image and duration is the duration of the animation. |
resize () | resizes the image. |
imageLoaded () | returns true if image is loaded. |
Static property | Description |
objs | array containing all the PinchZoomer objects. |
Static method | Description |
get (idOrIndex) | returns PinchZoomer instance given the index or id of the image. It is recommended that you use id instead of index to be sure you are getting the right instance. |
remove (idOrIndex) | removes PinchZoomer instance given the index or id of the image. This also removes the generated image. It is recommended that you use id instead of index to be sure you are getting the right instance. |
removeAll () | removes all PinchZoomer instances. This also removes the generated images for each instance. It is recommended that you use id instead of index to be sure you are getting the right instance. |
init (imgs, vars) | initializes and creates PinchZoomer instances given the imgs (jQuery selector) and vars (PinchZoomer options). This basically translates to $(imgs).pinchzoomer(vars) |
<img id="img1" src="assets/1.jpg" /> <img id="img2" src="assets/2.jpg" />Javascript and jQuery
//using static methods PinchZoomer.init("img"); // add multi-touch zoom to all images. Same code as $("img").pinchzoomer(); var pz1 = PinchZoomer.get("img1"); // or PinchZoomer.get(0) since img1 is the first instance PinchZoomer.remove("img2"); // removes image with id of 'img2' //using public methods of an instance pz1.resize(); // resize first instance //using public properties of an instance var image = pz1.image; // get the generated image of the first PinchZoomer instance console.log(image.attr("src")); // display url of image in console
This is perfect if you want to dynamically add images with zooming capability.
This is useful if you want to remove specific images or all images with zoom capability.
This can be used when you want to reload images dynamically(ex. using AJAX) and add zooming capability.