Allow for zoom on photo with mouse wheel
This commit is contained in:
parent
5a66c19e4f
commit
fcd23e7780
4 changed files with 82 additions and 23 deletions
|
@ -100,12 +100,14 @@
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
max-width: 100%;
|
|
||||||
max-height: 100%;
|
|
||||||
z-index: 6;
|
z-index: 6;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
|
max-width: none;
|
||||||
|
max-height: none;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
|
cursor: move;
|
||||||
|
box-shadow: 0 0 5px #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
#close, #right, #left, #fullscreen, #download {
|
#close, #right, #left, #fullscreen, #download {
|
||||||
|
@ -234,7 +236,7 @@
|
||||||
position: fixed;
|
position: fixed;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-color: #212121;
|
background-color: #212121aa;
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
assets/scripts/jquery.mousewheel.min.js
vendored
Normal file
8
assets/scripts/jquery.mousewheel.min.js
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/*!
|
||||||
|
* jQuery Mousewheel 3.1.13
|
||||||
|
*
|
||||||
|
* Copyright 2015 jQuery Foundation and other contributors
|
||||||
|
* Released under the MIT license.
|
||||||
|
* http://jquery.org/license
|
||||||
|
*/
|
||||||
|
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a:a(jQuery)}(function(a){function b(b){var g=b||window.event,h=i.call(arguments,1),j=0,l=0,m=0,n=0,o=0,p=0;if(b=a.event.fix(g),b.type="mousewheel","detail"in g&&(m=-1*g.detail),"wheelDelta"in g&&(m=g.wheelDelta),"wheelDeltaY"in g&&(m=g.wheelDeltaY),"wheelDeltaX"in g&&(l=-1*g.wheelDeltaX),"axis"in g&&g.axis===g.HORIZONTAL_AXIS&&(l=-1*m,m=0),j=0===m?l:m,"deltaY"in g&&(m=-1*g.deltaY,j=m),"deltaX"in g&&(l=g.deltaX,0===m&&(j=-1*l)),0!==m||0!==l){if(1===g.deltaMode){var q=a.data(this,"mousewheel-line-height");j*=q,m*=q,l*=q}else if(2===g.deltaMode){var r=a.data(this,"mousewheel-page-height");j*=r,m*=r,l*=r}if(n=Math.max(Math.abs(m),Math.abs(l)),(!f||f>n)&&(f=n,d(g,n)&&(f/=40)),d(g,n)&&(j/=40,l/=40,m/=40),j=Math[j>=1?"floor":"ceil"](j/f),l=Math[l>=1?"floor":"ceil"](l/f),m=Math[m>=1?"floor":"ceil"](m/f),k.settings.normalizeOffset&&this.getBoundingClientRect){var s=this.getBoundingClientRect();o=b.clientX-s.left,p=b.clientY-s.top}return b.deltaX=l,b.deltaY=m,b.deltaFactor=f,b.offsetX=o,b.offsetY=p,b.deltaMode=0,h.unshift(b,j,l,m),e&&clearTimeout(e),e=setTimeout(c,200),(a.event.dispatch||a.event.handle).apply(this,h)}}function c(){f=null}function d(a,b){return k.settings.adjustOldDeltas&&"mousewheel"===a.type&&b%120===0}var e,f,g=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],h="onwheel"in document||document.documentMode>=9?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],i=Array.prototype.slice;if(a.event.fixHooks)for(var j=g.length;j;)a.event.fixHooks[g[--j]]=a.event.mouseHooks;var k=a.event.special.mousewheel={version:"3.1.12",setup:function(){if(this.addEventListener)for(var c=h.length;c;)this.addEventListener(h[--c],b,!1);else this.onmousewheel=b;a.data(this,"mousewheel-line-height",k.getLineHeight(this)),a.data(this,"mousewheel-page-height",k.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var c=h.length;c;)this.removeEventListener(h[--c],b,!1);else this.onmousewheel=null;a.removeData(this,"mousewheel-line-height"),a.removeData(this,"mousewheel-page-height")},getLineHeight:function(b){var c=a(b),d=c["offsetParent"in a.fn?"offsetParent":"parent"]();return d.length||(d=a("body")),parseInt(d.css("fontSize"),10)||parseInt(c.css("fontSize"),10)||16},getPageHeight:function(b){return a(b).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})});
|
|
@ -1,11 +1,56 @@
|
||||||
var showcase = $("#img-big");
|
let showcase = $("#img-big");
|
||||||
var showcaseButton = $("#photo-buttons");
|
let showcaseButton = $("#photo-buttons");
|
||||||
var showcaseLink = $("#img_big_link");
|
let showcaseLink = $("#img_big_link");
|
||||||
var showcaseDownload = $("#img_big_download");
|
let showcaseDownload = $("#img_big_download");
|
||||||
var photoOverlay = $("#photo-overlay");
|
let photoOverlay = $("#photo-overlay");
|
||||||
var headerTop = $("#header-top");
|
let headerTop = $("#header-top");
|
||||||
var sideNav = $("#menuSidenav");
|
let sideNav = $("#menuSidenav");
|
||||||
var loading = $("#loading");
|
let loading = $("#loading");
|
||||||
|
|
||||||
|
$(document).ready(
|
||||||
|
function () {
|
||||||
|
showcase.bind("mousewheel", function(event, delta) {
|
||||||
|
let min_width = $(window).width() / 5;
|
||||||
|
let min_height = $(window).height() / 5;
|
||||||
|
let max_width = $(window).width() * 5;
|
||||||
|
let max_height = $(window).height() * 5;
|
||||||
|
|
||||||
|
let scale = 150 / 100;
|
||||||
|
if (delta < 0)
|
||||||
|
scale = 1/scale;
|
||||||
|
let cursorY = event.pageY - $(window).scrollTop();
|
||||||
|
let offsetX = event.pageX - (showcase.position().left + showcase.width()/2);
|
||||||
|
let offsetY = cursorY - (showcase.position().top + showcase.height()/2);
|
||||||
|
|
||||||
|
let new_width = showcase.width() * scale;
|
||||||
|
let new_height = showcase.height() * scale;
|
||||||
|
if (new_width > max_width || new_width < min_width)
|
||||||
|
new_width = 0;
|
||||||
|
if (new_height > max_height || new_height < min_height)
|
||||||
|
new_height = 0;
|
||||||
|
|
||||||
|
if (new_width !== 0 && new_height !== 0){
|
||||||
|
let new_left = event.pageX - (offsetX * scale);
|
||||||
|
let new_top = cursorY - (offsetY * scale);
|
||||||
|
|
||||||
|
showcase.width(new_width);
|
||||||
|
showcase.height(new_height);
|
||||||
|
|
||||||
|
if (new_height > $(window).height() || new_width > $(window).width()){
|
||||||
|
showcase.css('left', new_left +'px');
|
||||||
|
showcase.css('top', new_top +'px');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
showcase.css('left', $(window).width()/2 +'px');
|
||||||
|
showcase.css('top', $(window).height()/2 +'px');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display selected image in showcase
|
* Display selected image in showcase
|
||||||
|
@ -35,7 +80,7 @@ function closeBig() {
|
||||||
* Toggle display of buttons/header
|
* Toggle display of buttons/header
|
||||||
*/
|
*/
|
||||||
function toggleFullscreen() {
|
function toggleFullscreen() {
|
||||||
if (showcaseButton.css("display") == "none")
|
if (showcaseButton.css("display") === "none")
|
||||||
disableFullscreen();
|
disableFullscreen();
|
||||||
else
|
else
|
||||||
enableFullscreen();
|
enableFullscreen();
|
||||||
|
@ -59,7 +104,7 @@ function showTopBar() {
|
||||||
sideNav.fadeIn(500);
|
sideNav.fadeIn(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function () {
|
||||||
document.getElementById("photos_title").scrollIntoView();
|
document.getElementById("photos_title").scrollIntoView();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -67,8 +112,8 @@ $(document).ready(function() {
|
||||||
/*
|
/*
|
||||||
* Control images with keyboard arrows
|
* Control images with keyboard arrows
|
||||||
*/
|
*/
|
||||||
$(document).keydown(function(e) {
|
$(document).keydown(function (e) {
|
||||||
switch(e.which) {
|
switch (e.which) {
|
||||||
case 37: // left
|
case 37: // left
|
||||||
displayNext(-1);
|
displayNext(-1);
|
||||||
break;
|
break;
|
||||||
|
@ -77,7 +122,8 @@ $(document).keydown(function(e) {
|
||||||
displayNext(1);
|
displayNext(1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: return; // exit this handler for other keys
|
default:
|
||||||
|
return; // exit this handler for other keys
|
||||||
}
|
}
|
||||||
e.preventDefault(); // prevent the default action (scroll / move caret)
|
e.preventDefault(); // prevent the default action (scroll / move caret)
|
||||||
});
|
});
|
||||||
|
@ -94,19 +140,16 @@ var Swipe = new Hammer.Swipe();
|
||||||
manager.add(Swipe);
|
manager.add(Swipe);
|
||||||
|
|
||||||
// Subscribe to the swipe event
|
// Subscribe to the swipe event
|
||||||
manager.on('swipe', function(e) {
|
manager.on('swipe', function (e) {
|
||||||
var direction = e.offsetDirection;
|
var direction = e.offsetDirection;
|
||||||
if (direction === 4) { // right
|
if (direction === 4) { // right
|
||||||
displayNext(-1);
|
displayNext(-1);
|
||||||
} else if (direction === 2){ // left
|
} else if (direction === 2) { // left
|
||||||
displayNext(1);
|
displayNext(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display next/last image in showcase. When reaching end/start, loop back to start/end
|
* Display next/last image in showcase. When reaching end/start, loop back to start/end
|
||||||
*/
|
*/
|
||||||
|
@ -138,11 +181,15 @@ function displayNext(direction) {
|
||||||
*/
|
*/
|
||||||
function changeImage(thumb) {
|
function changeImage(thumb) {
|
||||||
displayLoading();
|
displayLoading();
|
||||||
showcase.on('load', function() {
|
showcase.on('load', function () {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
});
|
});
|
||||||
var source = getSourceFromThumbnail(thumb);
|
var source = getSourceFromThumbnail(thumb);
|
||||||
showcase.attr("src", source);
|
showcase.attr("src", source);
|
||||||
|
showcase.css({
|
||||||
|
width: 'auto',
|
||||||
|
height: '90%'
|
||||||
|
});
|
||||||
showcaseLink.attr("href", source);
|
showcaseLink.attr("href", source);
|
||||||
showcaseDownload.attr("href", source);
|
showcaseDownload.attr("href", source);
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,7 +220,8 @@ function generatePath($path)
|
||||||
?>
|
?>
|
||||||
<div id="photo-overlay" style="display:none">
|
<div id="photo-overlay" style="display:none">
|
||||||
|
|
||||||
<img src="" id="img-big" onclick="toggleFullscreen()">
|
<img src="" id="img-big">
|
||||||
|
|
||||||
<div id="close-back" onclick="closeBig()"></div>
|
<div id="close-back" onclick="closeBig()"></div>
|
||||||
<div id="loading" onclick="closeBig()">
|
<div id="loading" onclick="closeBig()">
|
||||||
<i class="fas fa-spinner fa-spin"></i>
|
<i class="fas fa-spinner fa-spin"></i>
|
||||||
|
@ -284,6 +285,7 @@ $pageTitle = "Photos";
|
||||||
ob_start(); // Start reading html
|
ob_start(); // Start reading html
|
||||||
?>
|
?>
|
||||||
<link rel="stylesheet" type="text/css" media="screen" href="assets/css/photos.css">
|
<link rel="stylesheet" type="text/css" media="screen" href="assets/css/photos.css">
|
||||||
|
<script type="text/javascript" src="assets/scripts/jquery.mousewheel.min.js"></script>
|
||||||
<?php
|
<?php
|
||||||
$pageMeta = ob_get_clean(); // Store html content in variable
|
$pageMeta = ob_get_clean(); // Store html content in variable
|
||||||
include("template.php"); // Display template with variable content
|
include("template.php"); // Display template with variable content
|
||||||
|
|
Loading…
Reference in a new issue