Hello!
I have build popup that is working fine, I need use it twice (one on click and second on mousemove) on same page, but events are working only with first popup (second on mousemove popup cant be closed).
Ive googled some info, and I tried manipulate it with loop, but I cant get it work (Im new in JS)… can anyone help me to get it work ?
Thanks you
// Pop-up
if (document.querySelector(".fl-pop-up")) {
window.addEventListener("load", function() {
var btn = document.getElementById("btn_fl-pop-up");
var modal = document.getElementById("fl-pop-up__init");
// Open if exist
if (btn) {
btn.onclick = function() {
modal.classList.add("fl-pop-up__active");
};
}
var modal__overlay = document.querySelector(".fl-pop-up__overlay");
var close = document.querySelector(".fl-pop-up__overlay--close");
// Close on close click
close.onclick = function() {
modal__overlay.classList.remove("fl-pop-up__active");
};
// Close on window click
window.onclick = function(event) {
if (event.target == modal__overlay) {
modal__overlay.classList.remove("fl-pop-up__active");
}
};
// Close on ESC
document.onkeydown = function(evt) {
evt = evt || window.event;
if (evt.keyCode == 27) {
modal__overlay.classList.remove("fl-pop-up__active");
}
};
});
}
// Abandoning visitor
var mouseX = 0;
var mouseY = 0;
var popupCounter = 0;
document.addEventListener("mousemove", function(e) {
mouseX = e.clientX;
mouseY = e.clientY;
var modal = document.getElementById("fl-pop-up__ab");
if (mouseY < 50) {
if (popupCounter < 1) {
modal.classList.add("fl-pop-up__active");
}
popupCounter++;
}
});