All the pictures come from Flickr website, copyright to the original author. You can play the following example by changing themes and options in the playground. Besides, examples collection can be found on CodePen.
The usage of magnify is very simple.
<link href="/path/to/magnify.css" rel="stylesheet"> <script src="/path/to/jquery.js"></script> <script src="/path/to/jquery.magnify.js"></script>
The icons in magnify use svg default, you can customize them in options.
The default structure as below:
<a data-magnify="gallery" href="big-1.jpg"> <img src="small-1.jpg"> </a> <a data-magnify="gallery" href="big-2.jpg"> <img src="small-2.jpg"> </a> <a data-magnify="gallery" href="big-3.jpg"> <img src="small-3.jpg"> </a>
or
<img data-magnify="gallery" data-src="big-1.jpg" src="small-1.jpg"> <img data-magnify="gallery" data-src="big-2.jpg" src="small-2.jpg"> <img data-magnify="gallery" data-src="big-3.jpg" src="small-3.jpg">
All structures above have optional attributes as below:
data-src
attribute to link big image if you do not want to use a
<a>
tag. If you use it in a
<a>
tag, it will override the image link in
href
attribute.
data-caption
attribute if you want to show a caption. If you are not using this
attribute, it will
show the image name in the
url when you set the
title
option
true
.
data-group
attribute if you want to set the images in groups.
If you add a
data-magnify
attribute, you can write none of js.
Of course, you can use selector to call the plugin as following code:
$('[data-magnify=gallery]').magnify(options);
Name | Type | Default | Description |
---|---|---|---|
draggable | boolean |
true
|
If ture, it allow modal dragging |
resizable | boolean |
true
|
If ture, it allow modal resizing. |
movable | boolean |
true
|
If ture, it allow image moving. |
keyboard | boolean |
true
|
If ture, it allow keyboard control. It is similar to Windows photo viewer.
← prev image → next image + zoom in image - zoom out image ctrl + alt + 0 image autual size ctrl + , rotate image left ctrl + . rotate image right Q close the Magnify modal |
title | boolean |
true
|
If ture, it will show image title on header. |
fixedModalSize | boolean |
false
|
If false, the modal init size will fit to image size. If true, the modal init size will be set with
|
modalWidth | number |
320
|
The modal min width. |
modalHeight | number |
320
|
The modal min height. |
gapThreshold | number |
0.02
|
There will have a gap if modal too big to beyond the browser. |
ratioThreshold | number |
0.01
|
Image zoom ratio threshold |
minRatio | number |
0.05 (5%)
|
The min ratio to show image. |
maxRatio | number |
16 (1600%)
|
The max ratio to show image. |
icons: { | |||
minimize | string |
svg
|
The minimize icon. |
maximize | string |
svg
|
The maximize icon. |
close | string |
svg
|
The close icon. |
zoomIn | string |
svg
|
The zoomIn icon. |
zoomOut | string |
svg
|
The zoomOut icon. |
prev | string |
svg
|
The prev icon. |
next | string |
svg
|
The next icon. |
fullscreen | string |
svg
|
The fullscreen icon. |
actualSize | string |
svg
|
The actualSize icon. |
rotateLeft | string |
svg
|
The rotateLeft icon. |
rotateRight | string |
svg
|
The rotateRight icon. |
} | |||
headerToolbar | array |
[
|
The buttons display in header toolbar. |
footerToolbar | array |
[
|
The buttons display in footer toolbar. |
fixedContent | boolean |
true
|
If true, the content will be fixed. |
i18n: { | |||
minimize | string |
minimize
|
The minimize button title text. |
maximize | string |
maximize
|
The maximize button title text. |
close | string |
close
|
The close button title text. |
zoomIn | string |
zoom-in
|
The zoomIn button title text. |
zoomOut | string |
zoom-out
|
The zoomOut button title text. |
prev | string |
prev
|
The prev button title text. |
next | string |
next
|
The next button title text. |
fullscreen | string |
fullscreen
|
The fullscreen button title text. |
actualSize | string |
actual-size
|
The actualSize button title text. |
rotateLeft | string |
rotate-left
|
The rotateLeft button title text. |
rotateRight | string |
rotate-right
|
The rotateRight button title text. |
} | |||
initMaximized | boolean |
false
|
If false, the modal size will be set of image size or what you set. If true, the modal size will be set maximized when init. |
multiInstances | boolean |
true
|
If true, it allow multiple instances. |
initEvent | string |
click
|
The event to init plugin. Another value is
|
initAnimation | boolean |
true
|
If false, it will not have animation at plugin's init. |
fixedModalPos | boolean |
false
|
If true, the modal position will be fixed when change images. |
zIndex | number |
1090
|
The modal style of z-index, it is useful with multiple instances. |
dragHandle | string |
' '
|
The handle of draggable. |
progressiveLoading | boolean |
true
|
If true, the image will be rendered progressively. |
customButtons | object |
{}
|
$('[data-magnify=gallery]').magnify({ footerToolbar: [ ... 'myCustomButton' ], customButtons: { myCustomButton: { text: 'custom!', title: 'custom!', click: function (context, e) { alert('clicked the custom button!'); } } } }); Each
|
You can define callbacks in callbacks
option. In each callback you can get the
Magnify
instance with this
or context
.
$("[data-magnify=gallery]").magnify({ callbacks: { beforeOpen: function(context){ // Will fire before modal is opened }, opened: function(context){ // Will fire after modal is opened }, beforeClose: function(context){ // Will fire before modal is closed }, closed: function(context){ // Will fire after modal is closed }, beforeChange: function(context, index){ // Will fire before image is changed // The argument index is the current image index of image group }, changed: function(context, index){ // Will fire after image is changed // The argument index is the next image index of image group } } });
Please report bugs via GitHub if you think you might have found a bug or if you have a feature suggestion.