NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gallery.vue 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template lang="pug">
  2. .gallery.f-col.center(v-if="fullscreengallery + 1 > 0")
  3. button(@click="hideGallery").hide hide
  4. ul
  5. li(v-for="(image, i) of images" :class="{ active: i === selected }")
  6. .image-wrapper.f-col.center
  7. img(:src="image")
  8. .controls.f-row
  9. button(@click="prev") <
  10. .f-grow
  11. button(@click="next") >
  12. </template>
  13. <script>
  14. export default {
  15. props: {
  16. images: { type: Array },
  17. fullscreengallery: { type: Number },
  18. },
  19. data() {
  20. return {
  21. selected: -1
  22. }
  23. },
  24. methods: {
  25. prev() {
  26. this.selected > 0 ? this.selected-- : this.selected = this.images.length - 1
  27. },
  28. next() {
  29. this.selected < this.images.length - 1 ? this.selected++ : this.selected = 0
  30. },
  31. hideGallery() {
  32. this.$emit('close')
  33. },
  34. interpretKeypress(e) {
  35. switch (e.key) {
  36. case 'ArrowRight':
  37. this.next()
  38. break
  39. case 'ArrowLeft':
  40. this.prev()
  41. break
  42. case 'Escape':
  43. this.hideGallery()
  44. break
  45. }
  46. }
  47. },
  48. watch: {
  49. fullscreengallery(newVal, oldVal) {
  50. this.selected = newVal
  51. }
  52. },
  53. mounted() {
  54. // Set the first selection
  55. this.selected = this.fullscreengallery
  56. window.addEventListener('keydown', this.interpretKeypress)
  57. },
  58. destroyed() {
  59. window.removeEventListener('keydown', this.interpretKeypress)
  60. }
  61. }
  62. </script>
  63. <style lang="postcss">
  64. .gallery
  65. position: fixed
  66. top: 0
  67. left: 0
  68. width: 100%
  69. height: 100%
  70. background-color: black
  71. z-index: 1001
  72. > *
  73. opacity: 100%
  74. position: relative
  75. z-index: 1011
  76. button.hide
  77. z-index: 1100
  78. ul
  79. list-style: none
  80. li
  81. display: none
  82. &.active
  83. display: block
  84. .image-wrapper
  85. height: 100%
  86. width: 50vw
  87. background-color: yellow
  88. h1
  89. color: green
  90. .controls
  91. position: absolute
  92. width: 100vw
  93. button
  94. height: 100vw
  95. padding: 1vw
  96. </style>