From 33e738990444c98e206313b6147f67dca633f2f1 Mon Sep 17 00:00:00 2001 From: "rohit.kumar-at-942428920331" <59276987+RohitKumarGit@users.noreply.github.com> Date: Tue, 24 Sep 2024 21:41:12 +0530 Subject: [PATCH] box position not changing on scroll fix --- floatype.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/floatype.js b/floatype.js index a2b5c9d..c91f55b 100644 --- a/floatype.js +++ b/floatype.js @@ -85,14 +85,17 @@ export function floatype(el, options = {}) { box.classList.add("floatype"); el.parentNode.insertBefore(box, el.nextSibling); + window.addEventListener("scroll", adjustBoxPosition); + } + function adjustBoxPosition(){ + const coords = getCaret(el); + box.style.left = `${coords.x}px`; + box.style.top = `${coords.y}px`; } - function renderResults() { box.innerHTML = ""; - const coords = getCaret(el); - box.style.left = `${coords.x}px`; - box.style.top = `${coords.y}px`; + adjustBoxPosition() items.forEach((item, idx) => { const div = document.createElement("div"); @@ -134,6 +137,7 @@ export function floatype(el, options = {}) { if (box) { box.remove(); box = null; + window.removeEventListener("scroll", adjustBoxPosition); } }