Zooming and Panning to the Image using jQuery and CSS3

We are going to create Zooming and Panning to the Image using jQuery and CSS3. This jQuery plugin is very simple to use. It allows the user to drag, pan, and zoom in/out in any elements of the web page using CSS3 and jQuery. You can also check the live demo of this simple tutorial, so you can get an idea and you can try this out, let's start coding.

How to use it

Create Markup

Create simple HTML source code for the zooming and panning of the image functionality.
  1. <div class="buttons">
  2.   <button class="zooming_In">Zoom In</button>
  3.   <button class="zooming_Out">Zoom Out</button>
  4.   <input type="range" class="zoom-range">
  5.   <button class="reset">Reset</button>
  6. </div>
And, create HTML Element you want to apply the zooming and panning.
  1. <div class="parent">
  2.   <div class="panzoom">
  3.     <img src="http://vignette4.wikia.nocookie.net/robber-penguin-agency/images/6/6e/Small-mario.png/revision/latest?cb=20150107080404">
  4.   </div>
  5. </div>

jQuery Script

Kindly add this simple jQuery script below your markup to fully functional.
  1. <script>
  2.   (function() {
  3.     var $section = $('section').first();
  4.     $section.find('.panzoom').panzoom({
  5.       $zoomIn: $section.find(".zooming_In"),
  6.       $zoomOut: $section.find(".zooming_Out"),
  7.       $zoomRange: $section.find(".zoom-range"),
  8.       $reset: $section.find(".reset")
  9.     });
  10.   })();
  11. </script>

Output

Result

Learn by Examples

Examples are better than thousands of words. Examples are often easier to understand than text explanations. Hope that this simple yet useful tutorial that I created may help you to your future projects. Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment