Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for image rotation and enhanced some features #9

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
eb10517
v2.0.2 - Fixed bug with data-big not enabled in images
jmalarcon Dec 18, 2018
8164c7e
Added to npm repository
jmalarcon Dec 26, 2018
fd0ffc3
Fixed typo
jmalarcon Dec 26, 2018
cf167ff
Fixed readme.md
jmalarcon Dec 27, 2018
dd98a0a
Enhanced icons, loading indicator
jmalarcon Feb 9, 2020
caa193d
Enhanced icons, loading indicator
jmalarcon Feb 9, 2020
a2b9cf2
WIP: adding rotation
jmalarcon Feb 9, 2020
3edaf69
Switched to cpy (cpx had unfixed security problems). Added onchange.
jmalarcon Feb 15, 2020
6fefb54
Added rotation support with transforms
jmalarcon Feb 15, 2020
91399d0
V3.0 - Support for image rotation
jmalarcon Feb 15, 2020
5f642ad
Fixed post compressjs npm task due to change of version in replace
jmalarcon Feb 15, 2020
fee1e5e
Bumped to 3.0.1 to publish on npm 😖
jmalarcon Feb 15, 2020
b907548
Bug fixed on returning panned elements to jQuery
jmalarcon Feb 15, 2020
361893f
Avoid keeping the rotation state. Enhanced icons
jmalarcon Feb 15, 2020
29f7798
Add .npmignore for enhanced publishing
jmalarcon Feb 17, 2020
492a1f3
Updated packages
jmalarcon Mar 29, 2020
7cb288f
Added file to .npmignore
jmalarcon Apr 17, 2020
21c1151
Changed information info
jmalarcon May 11, 2020
f1c1eed
Merge branch 'master' of https://github.com/saplumbaga/jquery.pan int…
jmalarcon Apr 20, 2022
7a1705d
Updated obsolete jQuey event methods
jmalarcon Apr 20, 2022
97721ea
Reduce button images sizes
jmalarcon Apr 20, 2022
355a423
Add support for links in the image
jmalarcon Apr 20, 2022
5fea991
v4.0.0
jmalarcon Apr 20, 2022
4e3bdd9
- Fix a bug with links
jmalarcon Apr 20, 2022
476eae3
1. Add pan capabilities to new images
MobCode100 Sep 1, 2022
c86b2cf
README Changes
MobCode100 Sep 1, 2022
fe536e8
README.md change
MobCode100 Sep 1, 2022
7900a75
v5.0:
jmalarcon Sep 2, 2022
6a914fe
Merge pull request #5 from MobCode100/master
jmalarcon Sep 2, 2022
bd3fa82
Fixed bug when minLoadingTime= 0 or missing
jmalarcon Feb 9, 2024
fb0c2a4
Update package.json prebuild task because of changes on rimraf.
jmalarcon Feb 29, 2024
e89b5db
v.6.0 - Add passive event handlers, svg images, no ie10, new option w…
jmalarcon Oct 4, 2024
7836d51
Ignore images in /img directory in npm package
jmalarcon Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.vscode
.gitattributes
index.html
src
/img/*
*.tgz
100 changes: 83 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
Fullscreen Image Zoom and Pan with Jquery
================================
# Fullscreen Image Zoom and Pan with Jquery

Original 1.x version written by [Samir Hazir](https://github.com/saplumbaga/jquery.pan). Version 2.x written by me.
>Original 1.x version written by [Samil Hazir](https://github.com/saplumbaga). Later enhanced versions written and maintained by [José M. Alarcón](https://github.com/jmalarcon).

Fullscreen Image Zoom and Pan with Jquery
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
- Auto-apn alongside pointer movement
- 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
- Support for mobile devices. You can pan dragging the zoomed image
- Support from IE8+ and modern desktop and mobile browsers
- 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 and the plugin on a page and initialize the plugin. See a working demo at [https://jmalarcon.github.io/jquery.pan/](https://jmalarcon.github.io/jquery.pan/) or check the `index.html` page of this repository.
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/](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:

Works with all versions of jQuery, from 1.x to the latest ones.
```bash
npm i jquery.pan
```

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

```html
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="css/jquery.pan.css" />
<script src="jquery.min.js"></script>
<script src="jquery.pan.js"></script>

<script type="text/javascript">
Expand All @@ -30,24 +37,83 @@ Works with all versions of jQuery, from 1.x to the latest ones.
</script>
```

If there's a `data-big` attribute in the element then that URL will be used for the zoomed image. If there's not, then it should be an `<img>` element and the `src` attribute 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.
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:

```html
<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" alt="" />
<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:

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

It only adds the zoom capability to images that are **smaller than their natural size**. The `pan()` method filters out the jQuery selection and returns a 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:
If you call it with a `false` value for the `showRotationControls` option, then the rotation controls will not be shown:

```js
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](https://jmalarcon.github.io/jquery.pan/).

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:

```javascript
$(function(){
$(".pan").pan().each(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:

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

## License
Copyright (c) 2016 Samil Hazir

Copyright (c) 2016 Samil Hazir, 2018-2024 José M. Alarcon
Dual licensed under the GPL and MIT licenses.
Binary file removed dist/css/img/close.png
Binary file not shown.
1 change: 1 addition & 0 deletions dist/css/img/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions dist/css/img/link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dist/css/img/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions dist/css/img/rotateaw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions dist/css/img/rotatecw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed dist/css/img/zoomIn.png
Binary file not shown.
1 change: 1 addition & 0 deletions dist/css/img/zoomIn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed dist/css/img/zoomOut.png
Binary file not shown.
1 change: 1 addition & 0 deletions dist/css/img/zoomOut.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dist/css/jquery.pan.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading