0.1.3 • Published 3 years ago

@buuug7/simplify-mask v0.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

simplify mask

Install

install @buuug7/simplify-mask package via npm, and then import from @buuug7/simplify-mask/index.css file.

npm install @buuug7/simplify-mask

Demo examples

Usage

interact with javascript

document.querySelector("#openMask").addEventListener("click", () => {
  let { instance, close } = showMask();
  
  // close mask 
  instance.addEventListener("click", () => {
    close();
  });
});

function showMask() {
  const mask = document.createElement("div");
  mask.className = "mask";
  document.body.appendChild(mask);
  document.body.style.overflow = "hidden";
  setTimeout(() => {
    mask.classList.add("show");
  }, 0);

  const close = (() => {
    // remove mask after transition end
    mask.addEventListener("transitionend", (e) => {
      const target = e.target;
      const contains = target.classList.contains("hide");
      if (contains) {
        document.body.removeChild(mask);
        document.body.style.overflow = "auto";
      }
    });

    return () => {
      mask.classList.remove("show");
      mask.classList.add("hide");
    };
  })();

  return { instance: mask, close };
}
0.1.3

3 years ago

0.1.2

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.5

4 years ago