Create magnifying glass zoom effect using jQuery magnify Plugin
You must have seen on many shopping website, You can zoom the product image to see the clear view of design, If you are looking for same effect then here I am going to share jquery plugin to add magnifying glass style zoom functionality to images. Magnify is a simple, lightweight jQuery plugin that adds a magnifying glass style zoom functionality to images. It is a useful feature to have for product images on ecommerce websites, or if you just want people to be able to zoom into an image without spawning additional overlays or popup windows that may cover your content.
Integrate magnifying glass zoom effect on website
Follow below quick steps to integrate magnifying glass style like zoom functionality on images.
Libraries
Include the magnify.css and jquery.magnify.js on along with jquery core library.
<!--CSS--> <link rel="stylesheet" href="magnify.css"> <!--JS--> <script src="//code.jquery.com/jquery-latest.min.js"></script> <script src="jquery.magnify.js"></script> |
You have complete control over the style and size of the lens by modifying magnify.css. Magnify has support for touch devices, but for a better zoom experience you can load the optional mobile plugin by uncommenting the last line above. It is recommended to load the JavaScript files at the bottom just before the closing </body> tag if possible.
HTML
The URI to the large image can be placed in the data-magnify-src attribute as shown below, or passed as the src option when calling the .magnify() function
<img src="product.jpg" class="zoom" data-magnify-src="product-large.jpg"> |
If the data-magnify-src attribute or src option is not used, then Magnify will try to grab the large image from the parent <a> tag. Example:
<a href="product-large.jpg"> <img src="product.jpg" class="zoom"> </a> |
NOTE: The large image needs to have the same aspect ratio as the main image.
JS
Finally call the .magnify() function on page zoom functionality on images.
$(function() { $('.zoom').magnify(); }); |
Destroy zoom effect
var $zoom = $('.zoom').magnify(); $zoom.destroy(); |
Use other default plugins function to control magnify effect
$(function() { $('.zoom').magnify({ 'src': '/images/product-large.jpg', 'speed': 100, 'timeout': -1, 'finalWidth': null, 'finalHeight': null, 'magnifiedWidth': null, 'magnifiedHeight': null, 'limitBounds': false, 'onload': function(){} }); }); |
See live demo and download source code.
DEMO | DOWNLOAD
Visit official github repository for more information and follow for future updates. Don’t forget to read license for using this plugin in your projects.