From b7359df3ce766019958ce9ab71fe4c6050b36a05 Mon Sep 17 00:00:00 2001 From: Boris Voropaev Date: Wed, 6 Dec 2023 12:26:09 +0300 Subject: [PATCH] esc for swiper --- .../swiper-gallery/swiper-gallery.component.scss | 16 ++++++++-------- .../swiper-gallery/swiper-gallery.component.ts | 14 +++++++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/app/_modules/widjet/swiper-gallery/swiper-gallery.component.scss b/src/app/_modules/widjet/swiper-gallery/swiper-gallery.component.scss index 02c1843..d4885c1 100644 --- a/src/app/_modules/widjet/swiper-gallery/swiper-gallery.component.scss +++ b/src/app/_modules/widjet/swiper-gallery/swiper-gallery.component.scss @@ -16,8 +16,11 @@ --swiper-pagination-color: #fff; >swiper{ height: 100%; - img { - object-fit:contain; + .slide{ + cursor:w-resize; + img { + object-fit:contain; + } } } } @@ -27,8 +30,7 @@ height: calc( 20% - 10px); cursor: pointer; img { - width: 100%; - height: 100%; + object-fit:cover; &:not(.active){ filter: brightness(50%); @@ -40,11 +42,9 @@ height: 100%; display: block; background-color: grey; - cursor:w-resize; img { - object-fit: cover; - width: 100%; - height: 100%; + width: 100%; + height: 100%; } } .swiper-close{ diff --git a/src/app/_modules/widjet/swiper-gallery/swiper-gallery.component.ts b/src/app/_modules/widjet/swiper-gallery/swiper-gallery.component.ts index c7d26ca..6b02ec8 100644 --- a/src/app/_modules/widjet/swiper-gallery/swiper-gallery.component.ts +++ b/src/app/_modules/widjet/swiper-gallery/swiper-gallery.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; +import { Component, EventEmitter, Input, Output, ViewChild, HostListener} from '@angular/core'; import SwiperCore, {Navigation, Pagination, SwiperOptions} from 'swiper'; import { SwiperComponent } from "swiper/angular"; SwiperCore.use([Navigation, Pagination]); @@ -12,9 +12,17 @@ export class SwiperGalleryComponent { @Input() items: any; @Input() start = 0; @Input() closing:boolean; + @Output() event = new EventEmitter() + @ViewChild('swiper', { static: false }) swiper?: SwiperComponent; @ViewChild('thumb', { static: false }) thumb?: SwiperComponent; + + @HostListener('window:keydown', ['$event']) + handleKeyDown(event: KeyboardEvent) { + if (event.key === 'Escape') this.event.emit('close') +} + public active:number; public single: boolean; @@ -36,7 +44,8 @@ export class SwiperGalleryComponent { freeMode: true, watchSlidesProgress: true, } - + + ngOnInit(){ this.active = this.start; this.single = this.items.length === 1; @@ -61,7 +70,6 @@ export class SwiperGalleryComponent { } close(){ - console.log('click') this.event.emit('close') } }