JSFiddle - React, Tailwind, and code Playground
by mesak
HTML
<script src="http://fancybox.net/js/fancybox-1.3.4/jquery.fancybox-1.3.4.js"></script>
<link rel="stylesheet" href="http://fancybox.net/js/fancybox-1.3.4/jquery.fancybox-1.3.4.css">
<p>
<a id="example1" href="http://farm5.static.flickr.com/4058/4252054277_f0fa91e026.jpg">
<img alt="example1" src="http://farm5.static.flickr.com/4058/4252054277_f0fa91e026_m.jpg" />
</a>
<a id="example2" href="http://farm3.static.flickr.com/2489/4234944202_0fe7930011.jpg">
<img alt="example2" src="http://farm3.static.flickr.com/2489/4234944202_0fe7930011_m.jpg" />
</a>
<a id="example3" href="http://farm3.static.flickr.com/2647/3867677191_04d8d52b1a.jpg">
<img alt="example3" src="http://farm3.static.flickr.com/2647/3867677191_04d8d52b1a_m.jpg" />
</a>
</p>
<img id="example4" src="http://farm3.static.flickr.com/2647/3867677191_04d8d52b1a.jpg" />
JavaScript
// Wheelzoom 1.1.2
// (c) 2012 jacklmoore.com | license: www.opensource.org/licenses/mit-license.php
!function($){
var transparentPNG = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==";
var defaults = {
zoom: 0.10
};
var wheel;
if ( document.onmousewheel !== undefined ) { // Webkit/Opera/IE
wheel = 'onmousewheel';
}
else if ( document.onwheel !== undefined) { // FireFox 17+
wheel = 'onwheel';
}
$.fn.wheelzoom = function(options){
var settings = $.extend({}, defaults, options);
if (!this[0] || !wheel || !('backgroundSize' in this[0].style)) { // IE8-
return this;
}
return this.each(function(){
var img = this,
$img = $(img);
function loaded() {
var width = $img.width(),
height = $img.height(),
bgWidth = width,
bgHeight = height,
bgPosX = 0,
bgPosY = 0,
offsetBorderX = parseInt($img.css('border-left-width'),10),
offsetBorderY = parseInt($img.css('border-top-width'),10),
offsetPaddingX = parseInt($img.css('padding-left'),10),
offsetPaddingY = parseInt($img.css('padding-top'),10);
function reset() {
bgWidth = width;
bgHeight = height;
bgPosX = bgPosY = 0;
updateBgStyle();
}
function updateBgStyle() {
if (bgPosX > 0) {
bgPosX = 0;
} else if (bgPosX < width - bgWidth) {
bgPosX = width - bgWidth;
}
if (bgPosY > 0) {
bgPosY = 0;
} else if (bgPosY < height - bgHeight) {
bgPosY = height - bgHeight;
}
img.style.backgroundSize = bgWidth + 'px ' + bgHeight + 'px';
img.style.backgroundPosition = (bgPosX+offsetPaddingX) + 'px ' + (bgPosY+offsetPaddingY) + 'px';
}
$img.css({
background: "url("+img.src+") 0 0 no-repeat",
backgroundSize: width+'px '+height+'px',
backgroundPosition: offsetPaddingX+'px '+offsetPaddingY+'px'
}).bind('wheelzoom.reset', reset);
// Explicitly set the size to the...