npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery.pan

v6.0.0

Published

Fullscreen Image Zoom, Pan and Rotate plugin for Jquery

Downloads

223

Readme

Fullscreen Image Zoom and Pan with Jquery

Original 1.x version written by Samil Hazir. Later enhanced versions written and maintained by José M. Alarcón.

Fullscreen image zoom, pan and rotation plugin for jQuery with support for links in the images.

Features:

  • Automatically add zoom and pan to any images or elements with images inside
  • Auto-pan alongside pointer movement
  • Zoom in and out support. You can increase or decrease the zoom level with specific buttons or with the mouse wheel
  • Image rotation support with zoom and pan
  • Link button to open links if the image has a wrapping link (in any parent element)
  • Support for mobile devices. You can pan by dragging the zoomed image
  • Support for all modern desktop and mobile browsers
  • v6.0 removed support for Internet Explorer ⚠️

Getting Started

Include jQuery 3.x and the plugin on a page and initialize the plugin, best after the page has fully loaded. See a working demo at https://jmalarcon.github.io/jquery.pan/ or check the index.html page of this repository. You can also use it as a dependency with npm by simply writing:

npm i jquery.pan

You must include a small CSS, jquery.pan.css that is in the dist/css folder too (536 bytes gzipped).

<link rel="stylesheet" href="css/jquery.pan.css" />
<script src="jquery.min.js"></script>
<script src="jquery.pan.js"></script>

<script type="text/javascript">
    $(function(){
        $(".pan").pan();
    })
</script>

If there's a data-big attribute in the element, then that URL will be used for the zoomed image instead of the current image. If there's not a data-big attribute, then it will zoom any <img> element inside the element that has the pan() method applied, and then the specific data-big or the src attributes will be used to zoom the image, since a lot of images are limited in size to fit in their container (for example with the max-width property). Check out the index.html sample file in the repo:

<a class="pan" data-big="img/big1.jpg" href="#">
   <img src="img/small1.jpg" alt="" >
</a>
<img class="pan" style="max-width:150px;" src="img/big2.jpg" >

Therefore you can use it to show images by clicking on elements, even it those don't are images or don't include images.

IMPORTANT: it only adds the zoom capability to images that are smaller than their natural size or that have a data-big attribute, since small images don't need it. This is by design, since this is not a carrousel kind of viewer, but an individual image viewer.

If a container element is selected to be zoomed, if it contains more than one image, every image will be zoomed and panned independently if there's at least one that needs zoom. In this case all of them will be zoomed, even if they don't need it because they are in their natural size. Check the sample page.

Disable image rotation

The pan() method takes an optional object with options to use for the page. They can only be specified in the first call to the plugin. They will be ignored in further calls so that the behavior of the plugin would be the same in all the images in the same page.

The available properties for this object in this version are:

  • showRotationControls: parameter to indicate if the rotation of images should be allowed or not.
  • minLoadingTime: indicates the minimum amount of time in milliseconds that the loading animation should be shown (by default it shows the images immediately as soon as they are loaded)
  • wheelZoomSpeed: the speed of the zoom when using the mouse wheel. It can be a number greater than 0. The default value is 100. It is the number of milliseconds between wheel events to speed up (lower values) or down (higher values) the zoom speed. It is useful to avoid zooming too fast or too slow with the mouse wheel in desktop or the touch event in mobile devices. If you set it to 0, the zoom speed will be too fast and it will be difficult to control the zoom level. If you set much higher than 200 or 300, it will be too slow to zoom in or out. It is recommended to set it between 50 and 200.

By default it shows the rotation controls:

$(".gallery img").pan();    //Rotation controls are shown and enabled

If you call it with a false value for the showRotationControls option, then the rotation controls will not be shown:

 var options = {
        showRotationControls : false,    //The rotation controls shouldn't be shown
        minLoadingTime: 400 //The minimum amount of time in ms the loading animation should be shown (by default it shows the images immediately)
    };
$(".gallery img").pan(options);    //No rotation controls, and images take at least 400ms to be shown

This is useful, for example in blogs or other environments where the images are manually added or reviewed and where images always have the right orientation. In those cases, disabling the rotation controls is a better option.

Links around images

Any images that are wrapped with a link (<a> element) will have a button in the viewer to open the link. Try it with any image from the fourth onwards in the sample page.

The link button in the viewer will use the same target attribute as the original wrapping link so that it will open in the right window. For example, if it has a target="_blank" attribute, the link button in the viewer will have this too ensuring it opens in a new tab.

The link button in the viewer will use the title attribute of the link to show a tooltip.

Returning value and call chaining

This pan() method filters out the jQuery selection and returns a new jQuery selection with the final elements that have been processed to have zoom & pan capabilities. You can further process them as usual with jQuery, for example:

$(function(){
    $(".mainContent img").pan().each(function() {
        $(this).attr('title', 'CLICK TO ZOOM');
    });
})

Dynamically add new images

Pan capabilities can be applied to newly added images. An example use case is to display user selected image files.

Just call pan on the new images:

// img variable is the image element
img.onload = function (){
    $(this).pan();
}

License

Copyright (c) 2016 Samil Hazir, 2018-2024 José M. Alarcon Dual licensed under the GPL and MIT licenses.