2020-11-27 23:02:59 +01:00
|
|
|
// https://forum.vuejs.org/t/how-to-use-helper-functions-for-imported-modules-in-vuejs-vue-template/6266/5
|
|
|
|
export default {
|
|
|
|
directives: {
|
|
|
|
lazy: {
|
2021-03-31 18:42:05 +02:00
|
|
|
bind (img, binding) {
|
|
|
|
// console.log('lazy bind', img, binding)
|
2020-12-23 19:11:46 +01:00
|
|
|
// show only the first image
|
2021-03-31 18:42:05 +02:00
|
|
|
if (binding.value === 0) {
|
2020-11-27 23:02:59 +01:00
|
|
|
img.setAttribute('src', img.getAttribute('data-src'))
|
|
|
|
img.removeAttribute('data-src')
|
|
|
|
img.classList.remove('lazy')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
switcher: {
|
2021-03-31 18:42:05 +02:00
|
|
|
inserted (el, binding) {
|
2020-11-27 23:02:59 +01:00
|
|
|
// switch images on mousemove
|
2021-03-31 18:42:05 +02:00
|
|
|
el.addEventListener('mousemove', function (event) {
|
|
|
|
const figs = this.querySelectorAll('figure')
|
|
|
|
// console.log('mousemove', this, event, figs.length)
|
2020-11-27 23:02:59 +01:00
|
|
|
// let len = figs.length
|
|
|
|
// let w = this.clientWidth;
|
|
|
|
// let g = w / len;
|
|
|
|
// let delta = Math.floor(event.layerX / g)
|
2021-03-31 18:42:05 +02:00
|
|
|
const delta = Math.floor(event.layerX / (this.clientWidth / figs.length))
|
|
|
|
// console.log('delta', delta)
|
2020-11-27 23:02:59 +01:00
|
|
|
figs.forEach((fig, index) => {
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log(index)
|
|
|
|
if (index === delta) {
|
2020-12-01 23:02:35 +01:00
|
|
|
// fig.style.display = "block"
|
2021-03-31 18:42:05 +02:00
|
|
|
fig.classList.remove('hide')
|
|
|
|
fig.classList.add('show')
|
|
|
|
} else {
|
2020-12-01 23:02:35 +01:00
|
|
|
// fig.style.display = "none"
|
2021-03-31 18:42:05 +02:00
|
|
|
fig.classList.remove('show')
|
|
|
|
fig.classList.add('hide')
|
2020-11-27 23:02:59 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-03-31 18:42:05 +02:00
|
|
|
mounted () {
|
2020-11-27 23:02:59 +01:00
|
|
|
// lazy load images on mouseover
|
2021-03-31 18:42:05 +02:00
|
|
|
console.log('card mounted', this.$options.name)
|
2020-12-23 19:11:46 +01:00
|
|
|
// if (this.$options.name ==! 'ModalCard') {
|
2021-03-31 18:42:05 +02:00
|
|
|
this.$el.addEventListener('mouseover', function (event) {
|
|
|
|
const imgs = this.querySelectorAll('.images figure img.lazy')
|
2021-04-05 12:45:58 +02:00
|
|
|
// console.log('mousemove', this, imgs)
|
2021-03-31 18:42:05 +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 })
|
2020-12-23 19:11:46 +01:00
|
|
|
// }
|
2020-11-27 23:02:59 +01:00
|
|
|
},
|
|
|
|
methods: {
|
2020-12-23 19:11:46 +01:00
|
|
|
activateLazyLoad () {
|
2021-03-31 18:42:05 +02:00
|
|
|
console.log('card activateLazyLoad', this.$options.name)
|
2020-12-23 19:11:46 +01:00
|
|
|
|
2021-03-31 18:42:05 +02:00
|
|
|
this.$el.addEventListener('mousemove', function (event) {
|
|
|
|
const imgs = this.querySelectorAll('.images figure img.lazy')
|
2021-04-05 12:45:58 +02:00
|
|
|
// console.log('mousemove', this, imgs)
|
2020-12-23 19:11:46 +01:00
|
|
|
imgs.forEach((img) => {
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('forEach img',img)
|
2020-12-23 19:11:46 +01:00
|
|
|
img.setAttribute('src', img.getAttribute('data-src'))
|
|
|
|
img.removeAttribute('data-src')
|
|
|
|
img.classList.remove('lazy')
|
|
|
|
})
|
2021-03-31 18:42:05 +02:00
|
|
|
}, { once: true })
|
2020-12-23 19:11:46 +01:00
|
|
|
}
|
2020-11-27 23:02:59 +01:00
|
|
|
// deg2rad (deg) {
|
|
|
|
// return deg * (Math.PI / 180)
|
|
|
|
// },
|
|
|
|
}
|
|
|
|
}
|