123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <template>
- <div class="scrolling-wrapper">
- <img
- @click="lightboxEffect(index)"
- v-for="(thumbnail, index) in thumbnails"
- :key="thumbnail"
- :src="thumbnail"
- style="height:150px; width:150px; object-fit: cover;"
- class="light-box__thumbnail"
- />
- <transition name="fade" mode="out-in">
- <div @click.stop="bg = !bg" class="light-box__bg" v-if="bg"></div>
- </transition>
-
- <div v-if="bg">
- <div class="light-box__close" @click.stop="bg = !bg"></div>
- <p class="light-box__count" v-if="count">
- {{currentImage + 1 }}/
- <span>{{ thumbnails.length}}</span>
- </p>
- <div @click="prev" class="light-box__prev light-box__btn"></div>
-
- <div v-if="bg" class="light-box__container">
- <transition name="fade" mode="out-in">
- <img
- :key="currentImage"
- :src="largeImages[currentImage]"
- class="light-box__container__img"
- />
- </transition>
- </div>
-
- <div class="light-box__caption" v-if="caption">
- <p v-if="captions[currentImage]">{{ captions[currentImage]}}</p>
- </div>
-
- <div @click="next" class="light-box__next light-box__btn"></div>
- </div>
- </div>
- </template>
-
- <script>
- export default {
- data() {
- return {
- bg: false,
- currentImage: 0,
- count: true
- };
- },
- props: {
- thumbnails: {
- type: Array,
- required: true
- },
- largeImages: {
- type: Array,
- required: true
- },
- captions: {
- type: Array,
- required: true
- },
- thumbnailsPath: {
- type: String,
- required: true
- },
- largePath: {
- type: String,
- required: true
- },
- caption: true
- },
- methods: {
- lightboxEffect(curr) {
- this.currentImage = curr;
- this.bg = !this.bg;
- },
- next() {
- if (this.currentImage < this.largeImages.length - 1) {
- // eslint-disable-next-line no-plusplus
- this.currentImage++;
- } else {
- this.currentImage = 0;
- }
- },
- prev() {
- if (this.currentImage > 0) {
- // eslint-disable-next-line no-plusplus
- this.currentImage--;
- } else {
- this.currentImage = this.largeImages.length - 1;
- }
- }
- }
- };
- </script>
-
- <style lang="scss">
- .fade-enter-active,
- .fade-leave-active {
- transition: opacity 0.2s;
- }
- .fade-enter,
- .fade-leave-to {
- opacity: 0;
- }
- .light-box {
- &__bg {
- position: fixed;
- left: 0;
- top: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0.89);
- z-index: 1000;
- }
-
- &__thumbnail {
- cursor: pointer;
- }
-
- &__close {
- padding: 10px;
- position: absolute;
- right: 5px;
- top: 10px;
- background-image: url(../../../public/img/ligthbox/close.svg);
- background-size: contain;
- background-position: center;
- }
- &__container {
- position: absolute;
- z-index: 2000;
- display: flex;
- justify-content: center;
- align-items: center;
- max-width: 700px;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- min-height: 800px;
- img {
- align-self: center;
- }
- }
- &__btn {
- background-size: contain;
- background-position: center;
- align-self: center;
- padding: 15px;
- }
-
- &__close,
- &__btn {
- cursor: pointer;
- }
-
- &__close,
- &__btn,
- &__caption,
- &__count {
- position: absolute;
- z-index: 3000;
- }
-
- &__next {
- background-image: url(../../../public/img/ligthbox/next.svg);
- right: 20px;
- }
- &__prev {
- background-image: url(../../../public/img/ligthbox/prev.svg);
- left: 20px;
- }
- &__next,
- &__prev {
- top: 50%;
- transform: translateY(-50%);
- }
-
- &__caption {
- bottom: 0;
- width: 100%;
- height: 50px;
- display: flex;
- align-items: center;
- color: #fff;
- font-size: 20px;
- justify-content: center;
- }
-
- &__count {
- left: 20px;
- font-size: 16px;
- color: #fff;
- top: 14px;
- padding: 0;
- margin: 0;
- }
- }
- </style>
|