Zoomable & Rotatable Image Viewer Plugin - jQuery Magnify
| File Size: | 207 KB |
|---|---|
| Views Total: | 17695 |
| Last Update: | |
| Publish Date: | |
| Official Website: | Go to website |
| License: | MIT |
Magnify is a simple and lightweight jQuery image viewer plugin used to display images in a zoomable, rotatable, draggable, and navigatable lightbox popup.
More features:
- Fullscreen view.
- Cross browser.
- Mobile friendly.
- Allows to maximize and minimize the lightbox popup.
- Responsive design.
- Zoom on mouse wheel.
- SVG icons.
How to use it:
1. Include the jQuery magnify plugin and other required resources on the web page.
<link href="dist/jquery.magnify.css" rel="stylesheet"> <script src="/path/to/cdn/jquery.min.js"></script> <script src="dist/jquery.magnify.js"></script>
2. Insert your images to the image viewer using the following attributes:
- data-magnify="gallery": required attribute
- data-caption: image caption
- data-group: used for multiple instance on the page
- data-src: if you want to use
<img>tag instead of<a>
<a data-magnify="gallery"
data-caption="Image Caption 1"
data-group=""
href="1.jpg">
<img src="thumb-1.jpg" alt="">
</a>
<a data-magnify="gallery"
data-caption="Image Caption 2"
data-group=""
href="2.jpg">
<img src="thumb-2.jpg" alt="">
</a>
<a data-magnify="gallery"
data-caption="Image Caption 3"
data-group=""
href="3.jpg">
<img src="thumb-3.jpg" alt="">
</a>
<!-- OR -->
<img src="thumb-1.jpg"
data-magnify="gallery"
data-caption="Image Caption 1"
data-src="1.jpg">
<img src="thumb-1.jpg"
data-magnify="gallery"
data-caption="Image Caption 1"
data-src="1.jpg">
<img src="thumb-1.jpg"
data-magnify="gallery"
data-caption="Image Caption 1"
data-src="1.jpg">
3. Call the function magnify() and done.
$('[data-magnify=gallery]').magnify();
4. Possible plugin options and callback functions to customize the image viewer.
$('[data-magnify=gallery]').magnify({
// Enable modal to drag
draggable: true,
// Enable modal to resize
resizable: true,
// Enable image to move
movable: true,
// Enable keyboard navigation
keyboard: true,
// Shows the title
title: true,
// Min width of modal
modalWidth: 320,
// Min height of modal
modalHeight: 320,
// Enable the page content fixed
fixedContent: true,
// Disable the modal size fixed
fixedModalSize: false,
// Disable the image viewer maximized on init
initMaximized: false,
// Threshold of modal to browser window
gapThreshold: 0.02,
// Threshold of image ratio
ratioThreshold: 0.1,
// Min ratio of image when zoom out
minRatio: 0.05,
// Max ratio of image when zoom in
maxRatio: 16,
// Toolbar options in header
headerToolbar: [
'maximize',
'close'
],
// Toolbar options in footer
footerToolbar: [
'zoomIn',
'zoomOut',
'prev',
'fullscreen',
'next',
'actualSize',
'rotateRight'
],
// Customize button icon
icons: {
minimize: '<svg viewBox="0 0 1024 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M1024 749.714v109.714c0 50.286\
-41.143 91.429-91.429 91.429h-841.143c-50.286 0-91.429-41.143\
-91.429-91.429v-109.714c0-50.286 41.143-91.429 91.429-91.429\
h841.143c50.286 0 91.429 41.143 91.429 91.429z"></path>\
</svg>',
maximize: '<svg viewBox="0 0 1024 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M146.286 804.571h731.429v-438.857\
h-731.429v438.857zM1024 164.571v694.857c0 50.286-41.143 91.429\
-91.429 91.429h-841.143c-50.286 0-91.429-41.143-91.429-91.429v\
-694.857c0-50.286 41.143-91.429 91.429-91.429h841.143c50.286 0 \
91.429 41.143 91.429 91.429z"></path>\
</svg>',
close: '<svg viewBox="0 0 804.5714285714286 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M741.714 755.429c0 14.286-5.714 \
28.571-16 38.857l-77.714 77.714c-10.286 10.286-24.571 16-38.857 16\
s-28.571-5.714-38.857-16l-168-168-168 168c-10.286 10.286-24.571 16\
-38.857 16s-28.571-5.714-38.857-16l-77.714-77.714c-10.286-10.286\
-16-24.571-16-38.857s5.714-28.571 16-38.857l168-168-168-168c-10.286\
-10.286-16-24.571-16-38.857s5.714-28.571 16-38.857l77.714-77.714\
c10.286-10.286 24.571-16 38.857-16s28.571 5.714 38.857 16l168 168 \
168-168c10.286-10.286 24.571-16 38.857-16s28.571 5.714 38.857 \
16l77.714 77.714c10.286 10.286 16 24.571 16 38.857s-5.714 28.571\
-16 38.857l-168 168 168 168c10.286 10.286 16 24.571 16 38.857z"></path>\
</svg>',
zoomIn: '<svg viewBox="0 0 950.8571428571428 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M585.143 457.143v36.571c0 9.714-8.571 \
18.286-18.286 18.286h-128v128c0 9.714-8.571 18.286-18.286 18.286\
h-36.571c-9.714 0-18.286-8.571-18.286-18.286v-128h-128c-9.714 0\
-18.286-8.571-18.286-18.286v-36.571c0-9.714 8.571-18.286 18.286\
-18.286h128v-128c0-9.714 8.571-18.286 18.286-18.286h36.571c9.714 0 \
18.286 8.571 18.286 18.286v128h128c9.714 0 18.286 8.571 18.286 \
18.286zM658.286 475.429c0-141.143-114.857-256-256-256s-256 114.857\
-256 256 114.857 256 256 256 256-114.857 256-256zM950.857 950.857\
c0 40.571-32.571 73.143-73.143 73.143-19.429 0-38.286-8-51.429\
-21.714l-196-195.429c-66.857 46.286-146.857 70.857-228 70.857\
-222.286 0-402.286-180-402.286-402.286s180-402.286 402.286-402.286 \
402.286 180 402.286 402.286c0 81.143-24.571 161.143-70.857 228\
l196 196c13.143 13.143 21.143 32 21.143 51.429z"></path>\
</svg>',
zoomOut: '<svg viewBox="0 0 950.8571428571428 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M585.143 457.143v36.571c0 9.714-8.571 \
18.286-18.286 18.286h-329.143c-9.714 0-18.286-8.571-18.286-18.286\
v-36.571c0-9.714 8.571-18.286 18.286-18.286h329.143c9.714 0 18.286 \
8.571 18.286 18.286zM658.286 475.429c0-141.143-114.857-256-256-256\
s-256 114.857-256 256 114.857 256 256 256 256-114.857 256-256z\
M950.857 950.857c0 40.571-32.571 73.143-73.143 73.143-19.429 0\
-38.286-8-51.429-21.714l-196-195.429c-66.857 46.286-146.857 70.857\
-228 70.857-222.286 0-402.286-180-402.286-402.286s180-402.286 \
402.286-402.286 402.286 180 402.286 402.286c0 81.143-24.571 161.143\
-70.857 228l196 196c13.143 13.143 21.143 32 21.143 51.429z"></path>\
</svg>',
prev: '<svg viewBox="0 0 914.2857142857142 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M877.714 512v73.143c0 38.857-25.714 \
73.143-66.857 73.143h-402.286l167.429 168c13.714 13.143 21.714 32 \
21.714 51.429s-8 38.286-21.714 51.429l-42.857 43.429c-13.143 13.143\
-32 21.143-51.429 21.143s-38.286-8-52-21.143l-372-372.571c-13.143\
-13.143-21.143-32-21.143-51.429s8-38.286 21.143-52l372-371.429c13.714\
-13.714 32.571-21.714 52-21.714s37.714 8 51.429 21.714l42.857 42.286\
c13.714 13.714 21.714 32.571 21.714 52s-8 38.286-21.714 52l-167.429 \
167.429h402.286c41.143 0 66.857 34.286 66.857 73.143z"></path>\
</svg>',
next: '<svg viewBox="0 0 841.1428571428571 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M841.143 548.571c0 19.429-7.429 38.286\
-21.143 52l-372 372c-13.714 13.143-32.571 21.143-52 21.143s-37.714\
-8-51.429-21.143l-42.857-42.857c-13.714-13.714-21.714-32.571-21.714\
-52s8-38.286 21.714-52l167.429-167.429h-402.286c-41.143 0-66.857\
-34.286-66.857-73.143v-73.143c0-38.857 25.714-73.143 66.857-73.143\
h402.286l-167.429-168c-13.714-13.143-21.714-32-21.714-51.429s8\
-38.286 21.714-51.429l42.857-42.857c13.714-13.714 32-21.714 51.429\
-21.714s38.286 8 52 21.714l372 372c13.714 13.143 21.143 32 21.143 \
51.429z"></path>\
</svg>',
fullscreen: '<svg viewBox="0 0 1097.142857142857 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M365.714 329.143c0 60.571-49.143 \
109.714-109.714 109.714s-109.714-49.143-109.714-109.714 49.143\
-109.714 109.714-109.714 109.714 49.143 109.714 109.714z\
M950.857 548.571v256h-804.571v-109.714l182.857-182.857 91.429 \
91.429 292.571-292.571zM1005.714 146.286h-914.286c-9.714 0\
-18.286 8.571-18.286 18.286v694.857c0 9.714 8.571 18.286 \
18.286 18.286h914.286c9.714 0 18.286-8.571 18.286-18.286\
v-694.857c0-9.714-8.571-18.286-18.286-18.286zM1097.143 164.571\
v694.857c0 50.286-41.143 91.429-91.429 91.429h-914.286c-50.286 \
0-91.429-41.143-91.429-91.429v-694.857c0-50.286 41.143-91.429 \
91.429-91.429h914.286c50.286 0 91.429 41.143 91.429 91.429z"></path>\
</svg>',
actualSize: '<svg viewBox="0 0 877.7142857142857 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M733.143 309.143l-202.857 202.857 \
202.857 202.857 82.286-82.286c10.286-10.857 26.286-13.714 40-8 \
13.143 5.714 22.286 18.857 22.286 33.714v256c0 20-16.571 36.571\
-36.571 36.571h-256c-14.857 0-28-9.143-33.714-22.857-5.714\
-13.143-2.857-29.143 8-39.429l82.286-82.286-202.857-202.857\
-202.857 202.857 82.286 82.286c10.857 10.286 13.714 26.286 8 \
39.429-5.714 13.714-18.857 22.857-33.714 22.857h-256c-20 0\
-36.571-16.571-36.571-36.571v-256c0-14.857 9.143-28 22.857\
-33.714 13.143-5.714 29.143-2.857 39.429 8l82.286 82.286 \
202.857-202.857-202.857-202.857-82.286 82.286c-6.857 6.857\
-16 10.857-25.714 10.857-4.571 0-9.714-1.143-13.714-2.857\
-13.714-5.714-22.857-18.857-22.857-33.714v-256c0-20 16.571\
-36.571 36.571-36.571h256c14.857 0 28 9.143 33.714 22.857 \
5.714 13.143 2.857 29.143-8 39.429l-82.286 82.286 202.857 \
202.857 202.857-202.857-82.286-82.286c-10.857-10.286-13.714\
-26.286-8-39.429 5.714-13.714 18.857-22.857 33.714-22.857h256\
c20 0 36.571 16.571 36.571 36.571v256c0 14.857-9.143 28-22.286 \
33.714-4.571 1.714-9.714 2.857-14.286 2.857-9.714 0-18.857-4\
-25.714-10.857z"></path>\
</svg>',
rotateLeft: '<svg viewBox="0 0 877.7142857142857 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M877.714 512c0 241.714-197.143 \
438.857-438.857 438.857-130.857 0-254.286-57.714-337.714-158.286\
-5.714-7.429-5.143-18.286 1.143-24.571l78.286-78.857c4-3.429 \
9.143-5.143 14.286-5.143 5.143 0.571 10.286 2.857 13.143 6.857 \
56 72.571 140 113.714 230.857 113.714 161.143 0 292.571-131.429 \
292.571-292.571s-131.429-292.571-292.571-292.571c-74.857 0\
-145.714 28.571-198.857 78.286l78.286 78.857c10.857 10.286 \
13.714 26.286 8 39.429-5.714 13.714-18.857 22.857-33.714 22.857\
h-256c-20 0-36.571-16.571-36.571-36.571v-256c0-14.857 9.143-28 \
22.857-33.714 13.143-5.714 29.143-2.857 39.429 8l74.286 73.714\
c80.571-76 189.714-121.143 302.286-121.143 241.714 0 438.857 \
197.143 438.857 438.857z"></path>\
</svg>',
rotateRight: '<svg viewBox="0 0 877.7142857142857 1024" class="svg-inline-icon">\
<path fill="currentColor" d="M877.714 146.286v256c0 20-16.571 \
36.571-36.571 36.571h-256c-14.857 0-28-9.143-33.714-22.857\
-5.714-13.143-2.857-29.143 8-39.429l78.857-78.857c-53.714\
-49.714-124.571-78.286-199.429-78.286-161.143 0-292.571 \
131.429-292.571 292.571s131.429 292.571 292.571 292.571\
c90.857 0 174.857-41.143 230.857-113.714 2.857-4 8-6.286 \
13.143-6.857 5.143 0 10.286 1.714 14.286 5.143l78.286 78.857\
c6.857 6.286 6.857 17.143 1.143 24.571-83.429 100.571-206.857 \
158.286-337.714 158.286-241.714 0-438.857-197.143-438.857\
-438.857s197.143-438.857 438.857-438.857c112.571 0 221.714 \
45.143 302.286 121.143l74.286-73.714c10.286-10.857 26.286\
-13.714 40-8 13.143 5.714 22.286 18.857 22.286 33.714z"></path>\
</svg>'
},
// Customize language of button title
i18n: {
minimize: 'minimize',
maximize: 'maximize',
close: 'close',
zoomIn: 'zoom-in(+)',
zoomOut: 'zoom-out(-)',
prev: 'prev(←)',
next: 'next(→)',
fullscreen: 'fullscreen',
actualSize: 'actual-size(Ctrl+Alt+0)',
rotateLeft: 'rotate-left(Ctrl+,)',
rotateRight: 'rotate-right(Ctrl+.)'
},
// Enable multiple instances
multiInstances: true,
// Init trigger event
initEvent: 'click',
// Enable animation
initAnimation: true,
// Disable modal position fixed when change images
fixedModalPos: false,
// Modal z-index
zIndex: 1090,
// Selector of drag handler
dragHandle: false,
// Callback events
callbacks: {
beforeOpen: $.noop,
opened: $.noop,
beforeClose: $.noop,
closed: $.noop,
beforeChange: $.noop,
changed: $.noop
},
// Load the image progressively
progressiveLoading: true,
// Custom Buttons
customButtons: {}
});
Changelog:
v1.6.2 (2021-03-18)
- Update
v1.6.1 (2020-09-19)
- improve callbacks arguments
- improve function name
v1.6.0 (2020-09-17)
- rename headToolbar to headerToolbar
- rename footToolbar to footerToolbar
- add custom buttons option
v1.5.1 (2019-12-26)
- improve setImgTitle function and formatting
- refactor: format svg icons string
v1.5.1 (2019-12-24)
- improve setImgTitle function and formatting
v1.5.0 (2019-10-09)
- Add RTL support
v1.4.4 (2019-07-14)
- Fix the zIndex issue when click close button.
v1.4.3 (2019-05-28)
- Fix image vertical middle issue
- Improve image loading code
2019-01-06
- v1.4.2
2018-12-08
- v1.4.0
2018-11-26
- Fixed image scale issue
2018-10-19
- Add svg icons & remove font-awesome
2018-08-15
- v1.1.0: Add IE8 rotating support
2018-07-19
- Fixed preloader icon bug on Firefox
2018-05-20
- v1.0.0: Fixed image z-index issue with other dialog; Added new callbacks
2018-05-19
- v0.8.1: Fixed image position issue when resizing modal
2018-04-16
- v0.8.0: Add dragHandle option
2018-03-25
- v0.7.0
2018-03-06
- change option ImgWithModalFixed to fixedModalPos
2018-03-03
- v0.6.4: update
2018-03-03
- v0.6.3: Fixed image numerical accuracy issue; Add fullscreen default background-color; code improvement.
2018-02-24
- v0.6.2: Add minimize btn & small fix
2018-02-04
- v0.5.0: Modified details when change images & small fix
2018-01-27
- v0.4.1: Add static constants
2018-01-25
- v0.4.0: Add mobile support; Fixed 'click' issue on mobile
2018-01-20
- Fixed overflow page bug
2018-01-19
- Fixed grabbing cursor issue
2018-01-18
- Add multiInstances option & Fixed cursor issue
2018-01-13
- Add initMaximized option & small fix
- Add grabbing cursor
2018-01-09
- Bugfix
2018-01-08
- Fixed grab cursor issue when resizable & rotatable
2018-01-05
- Add grab cursor when modal resized
2018-01-04
- Add i18n support & small fix
2018-01-02
- Bugfix
2018-01-01
- Add error handling callback when image is failed to load
2017-12-28
- Add method to get scrollbar width
2017-12-26
- Optimize the content fixed
2017-12-25
- Improvement.
2017-12-24
- Added more options
This awesome jQuery plugin is developed by nzbin. For more Advanced Usages, please check the demo page or visit the official website.











