2019-06-03 13:06:44 +02:00
|
|
|
<template>
|
|
|
|
<div class="card">
|
2019-06-10 18:30:48 +02:00
|
|
|
<header>
|
|
|
|
<h1>{{ item.title }}</h1>
|
|
|
|
<h4>{{ item.description }}</h4>
|
2019-06-12 13:21:06 +02:00
|
|
|
<span class="ref">{{ item.reference }}</span>
|
2019-06-10 18:30:48 +02:00
|
|
|
</header>
|
2019-06-11 18:04:46 +02:00
|
|
|
<section class="images" v-switcher>
|
|
|
|
<figure
|
|
|
|
v-for="(img, index) in item.images"
|
|
|
|
:key="img.url"
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
class="lazy"
|
|
|
|
v-lazy="index"
|
|
|
|
:data-src="img.url"
|
|
|
|
:title="img.title"
|
|
|
|
/>
|
|
|
|
<img class="blank" :src="blanksrc">
|
|
|
|
</figure>
|
2019-06-10 18:30:48 +02:00
|
|
|
</section>
|
2019-06-03 13:06:44 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "Card",
|
|
|
|
props: ['item'],
|
2019-06-11 18:04:46 +02:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`
|
|
|
|
}
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
lazy: {
|
|
|
|
bind(img,binding){
|
|
|
|
// console.log('lazy bind', img, binding);
|
|
|
|
if(binding.value === 0){
|
|
|
|
img.setAttribute('src', img.getAttribute('data-src'))
|
|
|
|
img.removeAttribute('data-src')
|
|
|
|
img.classList.remove('lazy')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
switcher: {
|
|
|
|
inserted(el,binding){
|
|
|
|
// switch images on mousemove
|
|
|
|
el.addEventListener('mousemove', function(event) {
|
|
|
|
let figs = this.querySelectorAll('figure')
|
|
|
|
// console.log('mousemove', this, event, figs.length);
|
|
|
|
// let len = figs.length
|
|
|
|
// let w = this.clientWidth;
|
|
|
|
// let g = w / len;
|
|
|
|
// let delta = Math.floor(event.layerX / g)
|
|
|
|
let delta = Math.floor(event.layerX / (this.clientWidth / figs.length))
|
|
|
|
// console.log('delta', delta);
|
|
|
|
figs.forEach((fig, index) => {
|
|
|
|
// console.log(index);
|
|
|
|
if(index == delta){
|
|
|
|
fig.style.display = "block"
|
|
|
|
}else{
|
|
|
|
fig.style.display = "none"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
// lazy load images on mouseover
|
|
|
|
this.$el.addEventListener('mouseover', function(event) {
|
|
|
|
let imgs = this.querySelectorAll('.images figure img.lazy')
|
2019-06-12 12:16:15 +02:00
|
|
|
// console.log('mouseover', this, imgs);
|
2019-06-11 18:04:46 +02:00
|
|
|
imgs.forEach((img) => {
|
|
|
|
// console.log('forEach img',img);
|
|
|
|
img.setAttribute('src', img.getAttribute('data-src'))
|
|
|
|
img.removeAttribute('data-src')
|
|
|
|
img.classList.remove('lazy')
|
|
|
|
})
|
|
|
|
}, {once : true})
|
|
|
|
}
|
2019-06-03 13:06:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2019-06-10 18:30:48 +02:00
|
|
|
|
2019-06-03 13:06:44 +02:00
|
|
|
</style>
|