Feature-rich Product Gallery With Image Zoom - xZoom

File Size: 1.35 MB
Views Total: 84469
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Feature-rich Product Gallery With Image Zoom - xZoom

xZoom is a responsive, touch-friendly jQuery zoom gallery plugin designed for e-commerce websites that enable you to generate a pretty nice product gallery with thumbnail navigation and smooth image zoom support.

Compatible with jQuery Fancybox and Magnific Popup plugins. Licensed under the Apache License 2.0.

How to use it:

1. Add the following required JavaScript and CSS files to the webpage.

<!-- JQUERY -->
<script src="jquery.min.js"></script>

<!-- CSS STYLE-->
<link rel="stylesheet" href="css/xzoom.css">

<!-- XZOOM JQUERY PLUGIN  -->
<script src="js/xzoom.min.js"></script>

2. Add the xzoom markup to your webpage as shown below. You can add more or less images to xzoom, this example shows how it works with 4 images.

  • xoriginal - the path to the big image, that will be used as zoomed image in zoom.
  • xpreview - optional, but when it is set up, this attribute used as the medium preview image, while the src attribute in this case will be used as the small thumbnail image. If this attribute is not set up, then src attribute will be used as the medium preview image.
  • xtitle - text string that will be used as caption and will be shown in zoom output window inside "div" container with titleClass. If this attribute is not used then xZoom will use regular title attribute of the image.
<img class="xzoom" src="path/to/preview_image_01.jpg" xoriginal="path/to/original_image_01.jpg" />

<div class="xzoom-thumbs">
  <a href="path/to/original_image_01.jpg">
    <img class="xzoom-gallery" width="80" src="path/to/thumbs_image_01.jpg"  xpreview="path/to/preview_image_01.jpg">
  </a>
  <a href="path/to/original_image_02.jpg">
    <img class="xzoom-gallery" width="80" src="path/to/preview_image_02.jpg">
  </a>
  <a href="path/to/original_image_03.jpg">
    <img class="xzoom-gallery" width="80" src="path/to/preview_image_03.jpg">
  </a>
  <a href="path/to/original_image_04.jpg">
    <img class="xzoom-gallery" width="80" src="path/to/preview_image_04.jpg">
  </a>
</div>

3. Initialize the zoom gallery on document ready.

$(".xzoom").xzoom();

4. All possible options with default values.

$(".xzoom").xzoom({

  // top, left, right, bottom, inside, lens, fullscreen, #ID
  position: 'right', 

  // inside, fullscreen
  mposition: 'inside', 

  // In the HTML structure, this option gives an ability to output xzoom element, to the end of the document body or relative to the parent element of main source image.
  rootOutput: true,

  // x/y offset
  Xoffset: 0,
  Yoffset: 0,

  // Fade in effect, when zoom is opening.
  fadeIn: true,

  // Fade transition effect, when switching images by clicking on thumbnails.
  fadeTrans: true,

  // Fade out effect, when zoom is closing.
  fadeOut: false,

  // Enable smooth effects
  smooth: true,

  // Smooth move effect of the big zoomed image in the zoom output window. 
  // The higher value will make movement smoother.
  smoothZoomMove: 3,

  // Smooth move effect of lens.
  smoothLensMove: 1,

  // Smooth move effect of scale.
  smoothScale: 6,

  // From -1 to 1, that means -100% till 100% scale
  defaultScale: 0, 

  // Scale on mouse scroll.
  scroll: true,

  // Tint color. Color must be provided in format like "#color". 
  tint: false,

  // Tint opacity from 0 to 1.
  tintOpacity: 0.5,

  // Lens color. Color must be provided in format like "#color". 
  lens: false,

  // Lens opacity from 0 to 1.
  lensOpacity: 0.5,

  // 'box', 'circle'
  lensShape: 'box', 

  // Custom width of zoom window in pixels.
  zoomWidth: 'auto',

  // Custom height of zoom window in pixels.
  zoomHeight: 'auto',

  // Class name for source "div" container.
  sourceClass: 'xzoom-source',

  // Class name for loading "div" container that appear before zoom opens, when image is still loading.
  loadingClass: 'xzoom-loading',

  // Class name for lens "div".
  lensClass: 'xzoom-lens',

  // Class name for zoom window(div).
  zoomClass: 'xzoom-preview',

  // Class name that will be added to active thumbnail image.
  activeClass: 'xactive',

  // With this option you can make a selection action on thumbnail by hover mouse point on it.
  hover: false,

  // Adaptive functionality.
  adaptive: true,

  // When selected position "inside" and this option is set to true, the lens direction of moving will be reversed.
  lensReverse: false,

  // Same as lensReverse, but only available when adaptive is true.
  adaptiveReverse: false,

  // Lens will collide and not go out of main image borders. This option is always false for position "lens".
  lensCollision: true,

  //  Output title/caption of the image, in the zoom output window.
  title: false,

  // Class name for caption "div" container.
  titleClass: 'xzoom-caption',

  // Zoom image output as background
  bg: false 
  
});

5. API methods.

  • xappend(jQuery_object) - this function can add new thumbnail to current xZoom instance. It will take as parameter 1, object that must be an image and passed as jQuery object.
  • gallery() - this function can be used for integration with gallery plugins, like "FancyBox" or "Magnific Popup", it returns an object with the next properties: index (current selected thumbnail. Starting from 0), ogallery (array of paths to original big images) and cgallery (array of paths to original big images. Order begins from current index)

6. Events.

// Function that is called on initialization step, that is binding an event "mouseenter" to the passed jQuery object "element" which is originnaly a main source image.
//  And giving a function that need to be called when event will be triggered "instance.openzoom".
instance.eventopen = function(element) {
  element.bind('mouseenter', instance.openzoom);
}

// Function that is called on the step when it is needed to bind an event to the element on which the leaving will be tracked.
instance.eventleave = function(element) {
  element.bind('mouseleave', instance.closezoom);
}

// Function that is called on the step when it is needed to bind an event to the element on which the moving will be tracked.
instance.eventmove = function(element) {
  element.bind('mousemove', instance.movezoom);
}

// Function that is called on the step when it is needed to bind an event to the element on which the scrolling for scale will be tracked.
instance.eventscroll = function(element) {
  element.bind('mousewheel DOMMouseScroll', instance.xscroll);
}

// Function that is called on the step when it is needed to bind an event to the element on which the click will be tracked.
instance.eventclick = function(element) {
  element.bind('click', function(event) {
    $('#main_image').trigger('click');
  });
}

// Function to open zoom, uses event.pageX and event.pageY as start location of lens.
instance.openzoom(event)

// Has no parameters, and simply closing the zoom.
instance.closezoom()

// This function also uses event.pageX and event.pageY to be able to provide movement of lens on the zoom.
instance.movezoom(event)

// This function is adapted for "mousewheel", "DOMMouseScroll" events and tested, and works fine on all major browsers. 
// But if you are using some custom events where you will call this function directly then you can use event.xdelta as delta with value 0 or 1 to tell the direction of scaling by 5% from each call, or event.xscale for exact scale with value from -1 to 1 (which means -100% to 100%) to set up exact scale of the zoom as you need.
instance.xscroll(event)

// Function that will delete original instance.event* functions by replacing them with blank functions and unbind default events on objects. 
// It can help you to clear default mouse binding events that xzoom already setup.
instance.eventunbind()

// Function that will restore original instance.event* functions.
instance.eventdefault()

Changelog:

2021-05-07

  • v1.0.15: Added min css version, version update

2018-07-19

  • v1.0.14: Fixed image size condition for openOnSmall option; Fixed image size condition for openOnSmall option

2018-06-14

  • v1.0.12: openOnSmall option not working fixed

2018-06-13

  • v1.0.11: fixed for small images.

2018-02-11

  • v1.0.10: Bugfix

2017-12-27

  • v1.0.9: Added lensCollision option

2017-08-03

  • v1.0.8: bg description corrected

2017-06-11

  • v1.0.7: fixed lens position bug

2017-03-21

  • v1.0.3: jquery version compatibility fixed; Lens motion problem fixed in FF

2017-03-20

  • v1.0.2

 


This awesome jQuery plugin is developed by payalord. For more Advanced Usages, please check the demo page or visit the official website.