Last active
November 20, 2020 13:12
-
-
Save sarojbelbase/90b0798e151de27cbde1f78ab992b91d to your computer and use it in GitHub Desktop.
VanillaJs way of toggling with font awesome bars and close icons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $ = function (selector, parent) { | |
return (parent ? parent : document).querySelector(selector); | |
}; | |
(function () { | |
$('[data-toggle="offcanvas"]').addEventListener("click", function () { | |
$(".offcanvas-collapse").classList.toggle("open"); | |
}); | |
$('[data-toggle="offsection"]').addEventListener("click", function () { | |
var toggler = $(".offcanvas-section-collapse").classList.toggle("open"); | |
if (toggler) { | |
$("span.toggler > i").classList.remove("fa-bars"); | |
$("span.toggler > i").classList.add("fa-close"); | |
} else { | |
$("span.toggler > i").classList.remove("fa-close"); | |
$("span.toggler > i").classList.add("fa-bars"); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment