1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

improving lightbox zooming

This commit is contained in:
Patrik J. Braun 2018-12-18 20:12:51 +01:00
parent 700c421af0
commit 135bdca095
4 changed files with 120 additions and 61 deletions

View File

@ -29,19 +29,20 @@ app-gallery-lightbox-photo {
} }
.navigation-arrow { .navigation-arrow {
width: 20%; width: 30px;
min-width: 60px; min-width: 60px;
height: 50%; height: 100px;
margin-top: 22vh; position: absolute;
position: static; top: calc(50% - 50px);
display: inline-block; display: inline-block;
padding: 15px; padding: 15px;
cursor: pointer; cursor: pointer;
font-size: xx-large; font-size: xx-large;
left: 0;
} }
.navigation-arrow span { .navigation-arrow span {
top: 43%; top: 20px;
} }
#controllers-container { #controllers-container {
@ -73,7 +74,8 @@ app-gallery-lightbox-photo {
} }
#rightArrow { #rightArrow {
float: right; right: 0;
left: auto;
text-align: right; text-align: right;
} }
@ -197,3 +199,20 @@ app-info-panel {
-moz-transition: all 0.3s ease-in-out; -moz-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out; -webkit-transition: all 0.3s ease-in-out;
} }
.controls-zoom {
bottom: 0;
position: absolute;
margin-bottom: 10px;
}
.zoom-progress-wrapper {
height: 11px;
border: 1px solid white;
padding: 0;
}
.zoom-progress {
height: 10px;
background: white;
}

View File

@ -63,49 +63,62 @@
(swipeleft)="zoom == 1 && nextImage()" (swipeleft)="zoom == 1 && nextImage()"
(swiperight)="zoom == 1 && prevImage()" (swiperight)="zoom == 1 && prevImage()"
(swipeup)="zoom == 1 && hide()" (swipeup)="zoom == 1 && hide()"
(click)="photo.playPause()"> (tap)="tap($event)"
(pan)="pan($event)"
(wheel)="wheel($event)"
<div class="navigation-arrow highlight" (click)="mediaElement.playPause()">
*ngIf="navigation.hasPrev && zoom == 1" title="key: left arrow" id="leftArrow" i18n-title
(click)="prevImage()"><span
class="oi oi-chevron-left"></span></div>
<div class="navigation-arrow highlight"
*ngIf="navigation.hasNext && zoom == 1" title="key: right arrow" id="rightArrow" i18n-title
(click)="nextImage()"><span
class="oi oi-chevron-right"></span></div>
<div class="controls controls-playback" *ngIf="activePhoto && activePhoto.gridPhoto.isPhoto()">
<span class="oi oi-media-pause highlight control-button"
[ngClass]="playBackState == 0 ? 'button-disabled':''"
(click)="pause()"
title="pause"></span>
<span
class="oi oi-media-play highlight control-button"
[ngClass]="playBackState == 1 ? 'button-active':''"
(click)="play()"
title="auto play"></span>
<span class="oi oi-media-skip-forward highlight control-button"
[ngClass]="playBackState == 2 ? 'button-active':''"
(click)="fastForward()"
title="fast auto play"></span>
</div>
<div class="controls controls-big-play" *ngIf=" activePhoto && activePhoto.gridPhoto.isVideo() && photo.Paused">
<span class="oi oi-media-play"></span>
</div>
</div> </div>
<div class="navigation-arrow highlight"
*ngIf="navigation.hasPrev && zoom == 1" title="key: left arrow" id="leftArrow" i18n-title
(click)="prevImage()"><span
class="oi oi-chevron-left"></span></div>
<div class="navigation-arrow highlight"
*ngIf="navigation.hasNext && zoom == 1" title="key: right arrow" id="rightArrow" i18n-title
(click)="nextImage()"><span
class="oi oi-chevron-right"></span></div>
<div class="controls controls-zoom row" *ngIf="zoom > 1">
<div class="zoom-progress-wrapper offset-1 col-10 col-md-4 offset-md-4">
<div class="zoom-progress"
[style.width.%]="(zoom-1)/(MAX_ZOOM-1)*100"></div>
</div>
</div>
<div class="controls controls-playback"
*ngIf="zoom == 1 && activePhoto && activePhoto.gridPhoto.isPhoto()">
<span class="oi oi-media-pause highlight control-button"
[ngClass]="playBackState == PlayBackStates.Paused ? 'button-disabled':''"
(click)="pause()"
title="pause"></span>
<span
class="oi oi-media-play highlight control-button"
[ngClass]="playBackState == PlayBackStates.Play ? 'button-active':''"
(click)="play()"
title="auto play"></span>
<span class="oi oi-media-skip-forward highlight control-button"
[ngClass]="playBackState == PlayBackStates.FastForward ? 'button-active':''"
(click)="fastForward()"
title="fast auto play"></span>
</div>
<div class="controls controls-big-play"
*ngIf="activePhoto && activePhoto.gridPhoto.isVideo() && mediaElement.Paused">
<span class="oi oi-media-play"></span>
</div>
<div class="controls controls-video row" *ngIf="activePhoto && activePhoto.gridPhoto.isVideo()"> <div class="controls controls-video row" *ngIf="activePhoto && activePhoto.gridPhoto.isVideo()">
<span class="oi col-1" <span class="oi col-1"
[ngClass]="!photo.Paused ? 'oi-media-pause':'oi-media-play'" [ngClass]="!mediaElement.Paused ? 'oi-media-pause':'oi-media-play'"
(click)="photo.playPause()"></span> (click)="mediaElement.playPause()"></span>
<input type="range" [(ngModel)]="photo.VideoProgress" <input type="range" [(ngModel)]="mediaElement.VideoProgress"
min="0" max="100" step="0.1" class="col video-progress"> min="0" max="100" step="0.1" class="col video-progress">
<span class="oi col-1" <span class="oi col-1"
[ngClass]="photo.Muted ? 'oi-volume-off':'oi-volume-high'" [ngClass]="mediaElement.Muted ? 'oi-volume-off':'oi-volume-high'"
(click)="photo.mute()"></span> (click)="mediaElement.mute()"></span>
<input type="range" <input type="range"
[(ngModel)]="photo.VideoVolume" min="0" max="1" step="0.1" [(ngModel)]="mediaElement.VideoVolume" min="0" max="1" step="0.1"
value="1" class="col-2 col-md-1 volume"> value="1" class="col-2 col-md-1 volume">
</div> </div>
</div> </div>

View File

@ -23,8 +23,6 @@ import {MediaDTO} from '../../../../common/entities/MediaDTO';
import {QueryParams} from '../../../../common/QueryParams'; import {QueryParams} from '../../../../common/QueryParams';
import {GalleryService} from '../gallery.service'; import {GalleryService} from '../gallery.service';
import {PhotoDTO} from '../../../../common/entities/PhotoDTO'; import {PhotoDTO} from '../../../../common/entities/PhotoDTO';
import {$e} from '@angular/compiler/src/chars';
import {Utils} from '../../../../common/Utils';
export enum LightboxStates { export enum LightboxStates {
Open = 1, Open = 1,
@ -32,6 +30,12 @@ export enum LightboxStates {
Closed = 3 Closed = 3
} }
export enum PlayBackStates {
Paused = 1,
Play = 2,
FastForward = 3
}
@Component({ @Component({
selector: 'app-gallery-lightbox', selector: 'app-gallery-lightbox',
styleUrls: ['./lightbox.gallery.component.css', './inputrange.css'], styleUrls: ['./lightbox.gallery.component.css', './inputrange.css'],
@ -39,6 +43,8 @@ export enum LightboxStates {
}) })
export class GalleryLightboxComponent implements OnDestroy, OnInit { export class GalleryLightboxComponent implements OnDestroy, OnInit {
readonly MAX_ZOOM=10;
@ViewChild('photo') mediaElement: GalleryLightboxMediaComponent; @ViewChild('photo') mediaElement: GalleryLightboxMediaComponent;
@ViewChild('lightbox') lightboxElement: ElementRef; @ViewChild('lightbox') lightboxElement: ElementRef;
@ViewChild('root') root: ElementRef; @ViewChild('root') root: ElementRef;
@ -60,7 +66,8 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit {
}; };
private timer: Observable<number>; private timer: Observable<number>;
private timerSub: Subscription; private timerSub: Subscription;
public playBackState = 0; public playBackState: PlayBackStates = PlayBackStates.Paused;
public PlayBackStates = PlayBackStates;
public controllersDimmed = false; public controllersDimmed = false;
public controllersAlwaysOn = false; public controllersAlwaysOn = false;
public controllersVisible = true; public controllersVisible = true;
@ -157,8 +164,10 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit {
} }
} }
@HostListener('pan', ['$event']) pan($event: any) {
dragging($event: any) { if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) {
return;
}
if (this.zoom === 1) { if (this.zoom === 1) {
return; return;
} }
@ -173,28 +182,42 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit {
} }
} }
@HostListener('window:wheel', ['$event']) wheel($event: any) {
onWheel($event: any) { if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) {
return;
}
this.showControls();
this.setZoom(this.zoom + ($event.deltaY < 0 ? this.zoom / 10 : -this.zoom / 10)); this.setZoom(this.zoom + ($event.deltaY < 0 ? this.zoom / 10 : -this.zoom / 10));
} }
@HostListener('pinch', ['$event']) @HostListener('pinch', ['$event'])
pinch($event: any) { pinch($event: any) {
if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) {
return;
}
this.showControls();
this.setZoom(this.prevZoom * $event.scale); this.setZoom(this.prevZoom * $event.scale);
} }
@HostListener('pinchend', ['$event']) @HostListener('pinchend', ['$event'])
pinchend($event: any) { pinchend($event: any) {
if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) {
return;
}
this.showControls();
this.setZoom(this.prevZoom * $event.scale); this.setZoom(this.prevZoom * $event.scale);
this.prevZoom = this.zoom; this.prevZoom = this.zoom;
} }
@HostListener('tap', ['$event']) tap($event: any) {
tao($event: any) { if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) {
return;
}
if ($event.tapCount < 2) { if ($event.tapCount < 2) {
return; return;
} }
this.showControls();
if (this.zoom > 1) { if (this.zoom > 1) {
this.setZoom(1); this.setZoom(1);
this.prevZoom = this.zoom; this.prevZoom = this.zoom;
@ -214,9 +237,13 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit {
if (zoom < 1) { if (zoom < 1) {
zoom = 1; zoom = 1;
} }
if (zoom > 10) { if (zoom > this.MAX_ZOOM) {
zoom = 10; zoom = this.MAX_ZOOM;
} }
if (this.zoom === zoom) {
return;
}
this.pause();
this.drag.x = this.drag.x / this.zoom * zoom; this.drag.x = this.drag.x / this.zoom * zoom;
this.drag.y = this.drag.y / this.zoom * zoom; this.drag.y = this.drag.y / this.zoom * zoom;
this.prevDrag.x = this.drag.x; this.prevDrag.x = this.drag.x;
@ -272,8 +299,8 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit {
if (this.zoom < 1) { if (this.zoom < 1) {
this.zoom = 1; this.zoom = 1;
} }
if (this.zoom > 10) { if (this.zoom > this.MAX_ZOOM) {
this.zoom = 10; this.zoom = this.MAX_ZOOM;
} }
fixDrag(this.drag); fixDrag(this.drag);
fixDrag(this.prevDrag); fixDrag(this.prevDrag);
@ -520,7 +547,7 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit {
this.navigateToPhoto(0); this.navigateToPhoto(0);
} }
}); });
this.playBackState = 1; this.playBackState = PlayBackStates.Play;
} }
isInfoPanelAnimating(): boolean { isInfoPanelAnimating(): boolean {
@ -569,7 +596,7 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit {
this.navigateToPhoto(0); this.navigateToPhoto(0);
} }
}); });
this.playBackState = 2; this.playBackState = PlayBackStates.FastForward;
} }
@ -633,7 +660,7 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit {
if (this.timerSub != null) { if (this.timerSub != null) {
this.timerSub.unsubscribe(); this.timerSub.unsubscribe();
} }
this.playBackState = 0; this.playBackState = PlayBackStates.Paused;
} }
private findPhotoComponent(media: MediaDTO): GalleryPhotoComponent { private findPhotoComponent(media: MediaDTO): GalleryPhotoComponent {

View File

@ -41,13 +41,13 @@ export class GalleryLightboxMediaComponent implements OnChanges {
} }
ngOnChanges() { ngOnChanges() {
this.imageLoaded = false;
this.imageLoadFinished = false;
this.setImageSize();
if (this.prevGirdPhoto !== this.gridMedia) { if (this.prevGirdPhoto !== this.gridMedia) {
this.prevGirdPhoto = this.gridMedia; this.prevGirdPhoto = this.gridMedia;
this.thumbnailSrc = null; this.thumbnailSrc = null;
this.photoSrc = null; this.photoSrc = null;
this.imageLoaded = false;
this.imageLoadFinished = false;
this.setImageSize();
} }
if (this.thumbnailSrc == null && this.gridMedia && this.ThumbnailUrl !== null) { if (this.thumbnailSrc == null && this.gridMedia && this.ThumbnailUrl !== null) {
FixOrientationPipe.transform(this.ThumbnailUrl, this.gridMedia.Orientation) FixOrientationPipe.transform(this.ThumbnailUrl, this.gridMedia.Orientation)