|
| 1 | +<template lang="html"> |
| 2 | + <page |
| 3 | +title="Lightbox" |
| 4 | +intro="a modal image gallery (lightbox) with CSS and JavaScript" |
| 5 | +class="lightbox-page"> |
| 6 | + |
| 7 | + <template slot="header"> |
| 8 | + <h2class="title">Lightbox (Modal Image Gallery)</h2> |
| 9 | + <p>Click on one of the images to open the lightbox:</p> |
| 10 | + </template> |
| 11 | + |
| 12 | + <sample> |
| 13 | + <aclass="btn-modal"v-for="(slide, index) of slides"@click="openModal(index)"> |
| 14 | + <img:src="slide.thumbnail":alt="slide.text"width="300"height="200"> |
| 15 | + </a> |
| 16 | + <modal-box:is-active.sync="modal.isActive"> |
| 17 | + <divclass="modal-header"> |
| 18 | + <spanclass="close"@click="modal.isActive = false">×</span> |
| 19 | + </div> |
| 20 | + <divclass="modal-body"> |
| 21 | + <slideshow:active-index.sync="slideIndex":slides="slides"is-gallery></slideshow> |
| 22 | + </div> |
| 23 | + </modal-box> |
| 24 | + </sample> |
| 25 | + |
| 26 | + </page> |
| 27 | +</template> |
| 28 | + |
| 29 | +<script> |
| 30 | +importSlideshowfrom'@/components/images/Slideshow.vue' |
| 31 | +importModalBoxfrom'@/components/more/ModalBox.vue' |
| 32 | +
|
| 33 | +exportdefault { |
| 34 | + name:'lightbox-page', |
| 35 | +data: ()=> ({ |
| 36 | + modal: { |
| 37 | + isActive:false |
| 38 | + }, |
| 39 | + slideIndex:0, |
| 40 | + slides: [ |
| 41 | + { |
| 42 | + link:'https://www.w3schools.com/howto/img_nature_wide.jpg', |
| 43 | + thumbnail:'https://www.w3schools.com/howto/img_nature.jpg', |
| 44 | + text:'Nature and sunrise' |
| 45 | + }, |
| 46 | + { |
| 47 | + link:'https://www.w3schools.com/howto/img_fjords_wide.jpg', |
| 48 | + thumbnail:'https://www.w3schools.com/howto/img_fjords.jpg', |
| 49 | + text:'Trolltunga, Norway' |
| 50 | + }, |
| 51 | + { |
| 52 | + link:'https://www.w3schools.com/howto/img_mountains_wide.jpg', |
| 53 | + thumbnail:'https://www.w3schools.com/howto/img_mountains.jpg', |
| 54 | + text:'Mountains and fjords' |
| 55 | + }, |
| 56 | + { |
| 57 | + link:'https://www.w3schools.com/howto/img_lights_wide.jpg', |
| 58 | + thumbnail:'https://www.w3schools.com/howto/img_lights.jpg', |
| 59 | + text:'Northern Lights' |
| 60 | + } |
| 61 | + ] |
| 62 | + }), |
| 63 | + methods: { |
| 64 | +openModal(num) { |
| 65 | +this.modal.isActive=true |
| 66 | +this.slideIndex= num |
| 67 | + } |
| 68 | + }, |
| 69 | + components: { |
| 70 | + Slideshow, ModalBox |
| 71 | + } |
| 72 | +} |
| 73 | +</script> |
| 74 | + |
| 75 | +<style lang="scss"> |
| 76 | +.lightbox-page { |
| 77 | +.sample { |
| 78 | +.btn-modal { |
| 79 | +cursor:pointer; |
| 80 | +transition:.3s; |
| 81 | +padding-right:10px; |
| 82 | +
|
| 83 | +&:hover { |
| 84 | +opacity:0.7; |
| 85 | + } |
| 86 | +
|
| 87 | +& >img { |
| 88 | +border-radius:5px; |
| 89 | + } |
| 90 | + } |
| 91 | +
|
| 92 | +.modal-box { |
| 93 | +background-color:rgba(0,0,0,0.9); |
| 94 | +
|
| 95 | +.modal-content { |
| 96 | +background-color:transparent; |
| 97 | +border:none; |
| 98 | +box-shadow:none; |
| 99 | +
|
| 100 | +.modal-header { |
| 101 | +background-color:inherit; |
| 102 | +text-align:right; |
| 103 | +
|
| 104 | +.close { |
| 105 | +font-size:35px; |
| 106 | +float:none; |
| 107 | + } |
| 108 | + } |
| 109 | +
|
| 110 | +.modal-body { |
| 111 | +.gallery-container { |
| 112 | +margin:auto; |
| 113 | +
|
| 114 | +.column { |
| 115 | +max-width:100%; |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | +} |
| 123 | +</style> |