const cardsAnim = document.querySelectorAll('.card_js')
const cardsContentAnim = document.querySelectorAll('.card-contanet_js')
for (let index = 0; index < cardsAnim.length; index++) {
const card = cardsAnim[index]
const cardContent = cardsContentAnim[index]
card.addEventListener('mouseenter', (e) => {
let cardRect = card.getBoundingClientRect()
let relX = e.pageX - cardRect.left
let relY = e.pageY - cardRect.top - getBodyScrollTop()
let cardHeight = (cardRect.height + 100) / 2
let cardWeight = cardRect.width / 2
console.log(relX, cardRect.left, e.pageX)
const zone = zonexy( e.pageX, e.pageY, cardRect );
cardContent.innerText = zone;
if ( zone === 'top' ) {
cardContent.style.top = '-100%'
cardContent.style.left = '0'
cardContent.style.transition = '0s top ease'
setTimeout(() => {
cardContent.style.top = '0'
cardContent.style.transition = '0.3s top ease'
}, 0)
} else if ( zone === 'bottom' ) {
cardContent.style.top = '100%'
cardContent.style.left = '0'
cardContent.style.transition = '0s top ease'
setTimeout(() => {
cardContent.style.top = '0'
cardContent.style.transition = '0.3s top ease'
}, 0)
} else if ( zone === 'left' ) {
cardContent.style.left = '-100%'
cardContent.style.top = '0'
cardContent.style.transition = '0s left ease'
setTimeout(() => {
cardContent.style.left = '0'
cardContent.style.transition = '0.3s left ease'
}, 0)
} else if ( zone === 'right' ) {
cardContent.style.left = '100%'
cardContent.style.top = '0'
cardContent.style.transition = '0s left ease'
setTimeout(() => {
cardContent.style.left = '0'
cardContent.style.transition = '0.3s left ease'
}, 0)
}
})
card.addEventListener('mouseleave', (e) => {
let cardRect = card.getBoundingClientRect()
let relX = e.pageX - cardRect.left
let relY = e.pageY - cardRect.top - getBodyScrollTop()
let cardHeight = (cardRect.height + 100) / 2
let cardWeight = cardRect.width / 2
if (relY < cardHeight) {
cardContent.style.transition = '0s top ease'
cardContent.style.left = '0'
setTimeout(() => {
cardContent.style.top = '-100%'
cardContent.style.transition = '0.3s top ease'
}, 0)
} else if (relY > cardHeight) {
cardContent.style.transition = '0s top ease'
cardContent.style.left = '0'
setTimeout(() => {
cardContent.style.top = '100%'
cardContent.style.transition = '0.3s top ease'
}, 0)
} else if (relX < cardWeight) {
cardContent.style.transition = '0s left ease'
cardContent.style.top = '0'
setTimeout(() => {
cardContent.style.left = '-100%'
cardContent.style.transition = '0.3s left ease'
}, 0)
} else if (relX > cardWeight) {
cardContent.style.transition = '0s left ease'
cardContent.style.top = '0'
setTimeout(() => {
cardContent.style.left = '100%'
cardContent.style.transition = '0.3s left ease'
}, 0)
}
})
}
function getBodyScrollTop() {
return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop)
}
function zonexy( x, y, {top,left,bottom,right} ) {
const lx = x - left;
const rx = right - x;
const ty = y - top;
const by = bottom - y;
if( lx < rx ) {
if( ty < by ) {
if( lx < ty ) return 'left';
else return 'top';
}else{
if( lx < by ) return 'left';
else return 'bottom';
}
}else{
if( ty < by ) {
if( rx < ty ) return 'right';
else return 'top';
}else{
if( rx < by ) return 'right';
else return 'bottom';
}
}
}
(function f( s, v, d, c ) {
const se = document.querySelector( s );
const de = document.querySelector( d );
if( se.selectedOptions[0].value === v ) {
de.classList.remove( c );
}else{
setTimeout( f, 500, s, v, d, c );
}
})('.wpcf7-form-control', 'Instagram and MB', '.form-item.another_jeweler.d-none', 'd-none');