export class Fx1 {
DOM = {
el: null,
bottom: null,
top: null
}
constructor(DOM_el) {
this.DOM.el = DOM_el;
this.layout();
}
layout() {
/*
this
becomes
*/
// get element background-image url
const url = getComputedStyle(this.DOM.el).backgroundImage.match(/url\(["']?([^"']*)["']?\)/)[1];
gsap.set(this.DOM.el, {backgroundImage: 'none'});
const iterations = 2;
let innerHTML = '';
for (let i = 0; i < iterations; ++i) {
innerHTML += ``;
}
this.DOM.el.innerHTML = innerHTML;
this.DOM.bottom = this.DOM.el.querySelector('.double__img:first-child');
this.DOM.top = this.DOM.el.querySelector('.double__img:last-child');
gsap.set(this.DOM.bottom, {
scale: 1.15
});
}
mouseenter() {
if ( this.leaveTimeout ) {
this.leaveTimeout.kill();
}
this.enterTimeout = gsap.timeline({
defaults: {
duration: 0.7,
ease: 'power3.inOut',
},
})
.set(this.DOM.bottom, {willChange: 'filter'})
.set(this.DOM.top, {willChange: 'clip-path'})
.fromTo(this.DOM.top, {
clipPath: 'polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)',
}, {
clipPath: 'polygon(0% 0%, 0% 0%, 0% 100%, 0% 100%)'
}, 0)
.fromTo(this.DOM.bottom, {
filter: 'brightness(400%) saturate(200%) hue-rotate(190deg)',
}, {
filter: 'brightness(100%) saturate(100%) hue-rotate(0deg)',
}, 0)
}
mouseleave() {
if ( this.enterTimeout ) {
this.enterTimeout.kill();
}
this.leaveTimeout = gsap.timeline({
defaults: {
duration: 0.7,
ease: 'power3.inOut',
},
})
.set(this.DOM.bottom, {willChange: 'filter'})
.set(this.DOM.top, {willChange: 'clip-path'})
.to(this.DOM.top, {
clipPath: 'polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)'
}, 0)
.to(this.DOM.bottom, {
filter: 'brightness(400%) saturate(200%) hue-rotate(190deg)',
}, 0)
}
}