From 40b11cc3b7b2fccb98b39989b261c390ac0fd595 Mon Sep 17 00:00:00 2001 From: Shuhan Hu <1119han@gmail.com> Date: Tue, 28 Apr 2020 13:02:52 +0800 Subject: [PATCH] Active navbar-burger for mobile --- index.html | 2 +- index.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 index.js diff --git a/index.html b/index.html index f3352be..b82d996 100755 --- a/index.html +++ b/index.html @@ -125,7 +125,7 @@

--> + diff --git a/index.js b/index.js new file mode 100644 index 0000000..316a6f1 --- /dev/null +++ b/index.js @@ -0,0 +1,19 @@ +document.addEventListener("DOMContentLoaded", () => { + const $navbarBurgers = Array.prototype.slice.call( + document.querySelectorAll(".navbar-burger"), + 0 + ); + + if ($navbarBurgers.length > 0) { + console.log("$navbarBurgers.length"); + $navbarBurgers.forEach(el => { + el.addEventListener("click", () => { + const target = el.dataset.target; + const $target = document.getElementById(target); + + el.classList.toggle("is-active"); + $target.classList.toggle("is-active"); + }); + }); + } +});