JSFiddle - React, Tailwind, and code Playground
HTML
<h2>Klik op mij!</h2>
<p><span class='zoom' id='ex1'>
<span>Hover</span>
<img src='http://www.filmtotaal.nl/images/newscontent/4w7xpgykk7je_full.jpg' width='555' height='320' alt='Daisy on the Ohoopee'>
</span></p>
<hr>
CSS
.zoom {
display:inline-block;
position: relative;
}
/* magnifying glass icon */
.zoom:after {
content:'';
display:block;
width:33px;
height:33px;
position:absolute;
top:0;
right:0;
background:url(https://raw.github.com/jackmoore/zoom/master/icon.png);
}
.zoom img {
display: block;
}
.zoom img::selection { background-color: transparent; }
#ex1 { margin-right:5px; }
#ex2 img:hover { cursor: url(grab.cur), default; }
#ex2 img:active { cursor: url(grabbed.cur), default; }
#ex1 span, #ex2 span { position:absolute; top:3px; right:28px; color:#555; font:bold 13px/1 sans-serif; }
JavaScript
/*!
Zoom v1.7.12 - 2014-02-12
Enlarge images on click or mouseover.
(c) 2014 Jack Moore - http://www.jacklmoore.com/zoom
license: http://www.opensource.org/licenses/mit-license.php
*/
(function ($) {
var defaults = {
url: false,
callback: false,
target: false,
duration: 120,
on: 'mouseover', // other options: grab, click, toggle
touch: true, // enables a touch fallback
onZoomIn: false,
onZoomOut: false,
magnify: 1
};
// Core Zoom Logic, independent of event listeners.
$.zoom = function(target, source, img, magnify) {
var targetHeight,
targetWidth,
sourceHeight,
sourceWidth,
xRatio,
yRatio,
offset,
position = $(target).css('position');
// The parent element needs positioning so that the zoomed element can be correctly positioned within.
$(target).css({
position: /(absolute|fixed)/.test(position) ? position : 'relative',
overflow: 'hidden'
});
img.style.width = img.style.height = '';
$(img)
.addClass('zoomImg')
.css({
position: 'absolute',
top: 0,
left: 0,
opacity: 0,
width: img.width * magnify,
height: img.height * magnify,
border: 'none',
maxWidth: 'none',
maxHeight: 'none'
})
.appendTo(target);
return {
init: function() {
targetWidth = $(target).outerWidth();
targetHeight = $(target).outerHeight();
if (source === target) {
sourceWidth = targetWidth;
sourceHeight = targetHeight;
} else {
sourceWidth = $(source).outerWidth();
sourceHeight = $(source).outerHeight();
}
xRatio = (img.width - targetWidth) / sourceWidth;
yRatio = (img.height - targetHeight) / sourceHeight;
offset = $(source).offset();
},
move: function (e) {
var left = (e.pageX - offset.left),
top = (e.pageY - offset.top);
top = Math.max(Math.min(top, sourceHeight), 0);
left = Math.max(Math.min(left, sourceWidth), 0);
img.style.left = (left * -xRatio) + 'px';
img.style.top = (top * -yRatio) +...