Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div>
  3.     <li id="fukui" class="items-list" @mousemove="setActiveClass($event)" @mouseleave="resetActive()">
  4.       <router-link to="/destinations/gaula" class="link-items" :title="boxTitle">
  5.         <ol class="items-list-wrap">
  6.           <li class="items-wrap " v-for="(img, index) in localImgArray" :class="{active:
  7.          isItemActive(index), inactive: !isItemActive(index)}">
  8.             <img :src="img.path"/>
  9.           </li>
  10.           <li class="items-cover"><img src="/images/destinations/gaula/image-box/thumb_cover.png" alt=""></li>
  11.         </ol>
  12.         <div class="link-items-ttl">
  13.           <h2><span class="vol">vol.{{ boxNumber }}</span><br><span class="location">{{ boxTitle }}</span></h2>
  14.           <hr>
  15.         </div>
  16.       </router-link>
  17.     </li>
  18.   </div>
  19. </template>
  20.  
  21. <script>
  22.   export default {
  23.     props: {
  24.       imgArray: {
  25.         type: Array,
  26.         default: function () { return [] }
  27.       },
  28.       boxTitle: String,
  29.       boxNumber: Number
  30.     } ,
  31.     data() {
  32.       return {
  33.         localImgArray: this.imgArray,
  34.         activeItem: 0 // Hold styr på den aktive item
  35.       }
  36.     },
  37.     name: 'image-box',
  38.     methods: {
  39.       setActiveClass(event) {
  40.         var b, c, d, e, f, columnWidth, thumbnailId;
  41.         b = $(event.currentTarget),
  42.           c = this.localImgArray.length,
  43.           d = b.offset(),
  44.           columnWidth = b.width(),
  45.           e = columnWidth / c,
  46.           thumbnailId = Math.floor((event.clientX - d.left) / e)
  47.           this.activeItem = thumbnailId < 0 ? 0 : thumbnailId // Set den aktive item til at være det index som musen 'peger' på
  48.       },
  49.       resetActive() {
  50.         this.activeItem = 0 // Item 0 er aktiv ved mouse out
  51.       },
  52.       isItemActive(index){
  53.         return index == this.activeItem // Er dette den aktive item? alle andre er inaktive
  54.       }
  55.     }
  56.   }
  57. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement