Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

lightBoxGallery.vue 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div class="scrolling-wrapper">
  3. <img
  4. @click="lightboxEffect(index)"
  5. v-for="(thumbnail, index) in thumbnails"
  6. :key="thumbnail"
  7. :src="thumbnail"
  8. style="height:150px; width:150px; object-fit: cover;"
  9. class="light-box__thumbnail"
  10. />
  11. <transition name="fade" mode="out-in">
  12. <div @click.stop="bg = !bg" class="light-box__bg" v-if="bg"></div>
  13. </transition>
  14. <div v-if="bg">
  15. <div class="light-box__close" @click.stop="bg = !bg"></div>
  16. <p class="light-box__count" v-if="count">
  17. {{currentImage + 1 }}/
  18. <span>{{ thumbnails.length}}</span>
  19. </p>
  20. <div @click="prev" class="light-box__prev light-box__btn"></div>
  21. <div v-if="bg" class="light-box__container">
  22. <transition name="fade" mode="out-in">
  23. <img
  24. :key="currentImage"
  25. :src="largeImages[currentImage]"
  26. class="light-box__container__img"
  27. />
  28. </transition>
  29. </div>
  30. <div class="light-box__caption" v-if="caption">
  31. <p v-if="captions[currentImage]">{{ captions[currentImage]}}</p>
  32. </div>
  33. <div @click="next" class="light-box__next light-box__btn"></div>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. bg: false,
  42. currentImage: 0,
  43. count: true
  44. };
  45. },
  46. props: {
  47. thumbnails: {
  48. type: Array,
  49. required: true
  50. },
  51. largeImages: {
  52. type: Array,
  53. required: true
  54. },
  55. captions: {
  56. type: Array,
  57. required: true
  58. },
  59. thumbnailsPath: {
  60. type: String,
  61. required: true
  62. },
  63. largePath: {
  64. type: String,
  65. required: true
  66. },
  67. caption: true
  68. },
  69. methods: {
  70. lightboxEffect(curr) {
  71. this.currentImage = curr;
  72. this.bg = !this.bg;
  73. },
  74. next() {
  75. if (this.currentImage < this.largeImages.length - 1) {
  76. // eslint-disable-next-line no-plusplus
  77. this.currentImage++;
  78. } else {
  79. this.currentImage = 0;
  80. }
  81. },
  82. prev() {
  83. if (this.currentImage > 0) {
  84. // eslint-disable-next-line no-plusplus
  85. this.currentImage--;
  86. } else {
  87. this.currentImage = this.largeImages.length - 1;
  88. }
  89. }
  90. }
  91. };
  92. </script>
  93. <style lang="scss">
  94. .fade-enter-active,
  95. .fade-leave-active {
  96. transition: opacity 0.2s;
  97. }
  98. .fade-enter,
  99. .fade-leave-to {
  100. opacity: 0;
  101. }
  102. .light-box {
  103. &__bg {
  104. position: fixed;
  105. left: 0;
  106. top: 0;
  107. right: 0;
  108. bottom: 0;
  109. background-color: rgba(0, 0, 0, 0.89);
  110. z-index: 1000;
  111. }
  112. &__thumbnail {
  113. cursor: pointer;
  114. }
  115. &__close {
  116. padding: 10px;
  117. position: absolute;
  118. right: 5px;
  119. top: 10px;
  120. background-image: url(../../../public/img/ligthbox/close.svg);
  121. background-size: contain;
  122. background-position: center;
  123. }
  124. &__container {
  125. position: absolute;
  126. z-index: 2000;
  127. display: flex;
  128. justify-content: center;
  129. align-items: center;
  130. max-width: 700px;
  131. left: 50%;
  132. top: 50%;
  133. transform: translate(-50%, -50%);
  134. min-height: 800px;
  135. img {
  136. align-self: center;
  137. }
  138. }
  139. &__btn {
  140. background-size: contain;
  141. background-position: center;
  142. align-self: center;
  143. padding: 15px;
  144. }
  145. &__close,
  146. &__btn {
  147. cursor: pointer;
  148. }
  149. &__close,
  150. &__btn,
  151. &__caption,
  152. &__count {
  153. position: absolute;
  154. z-index: 3000;
  155. }
  156. &__next {
  157. background-image: url(../../../public/img/ligthbox/next.svg);
  158. right: 20px;
  159. }
  160. &__prev {
  161. background-image: url(../../../public/img/ligthbox/prev.svg);
  162. left: 20px;
  163. }
  164. &__next,
  165. &__prev {
  166. top: 50%;
  167. transform: translateY(-50%);
  168. }
  169. &__caption {
  170. bottom: 0;
  171. width: 100%;
  172. height: 50px;
  173. display: flex;
  174. align-items: center;
  175. color: #fff;
  176. font-size: 20px;
  177. justify-content: center;
  178. }
  179. &__count {
  180. left: 20px;
  181. font-size: 16px;
  182. color: #fff;
  183. top: 14px;
  184. padding: 0;
  185. margin: 0;
  186. }
  187. }
  188. </style>