Last active
October 14, 2018 17:01
-
-
Save wikimatze/0fac07c1d687b1377b8e695b04f4ad6c to your computer and use it in GitHub Desktop.
padrino blog tutorial application js
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
document.addEventListener('DOMContentLoaded', function () { | |
// Get all "navbar-burger" elements | |
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0); | |
// Check if there are any navbar burgers | |
if ($navbarBurgers.length > 0) { | |
// Add a click event on each of them | |
$navbarBurgers.forEach(function ($el) { | |
$el.addEventListener('click', function () { | |
// Get the target from the "data-target" attribute | |
var target = $el.dataset.target; | |
var $target = document.getElementById(target); | |
// Toggle the class on both the "navbar-burger" and the "navbar-menu" | |
$el.classList.toggle('is-active'); | |
$target.classList.toggle('is-active'); | |
}); | |
}); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment