hugo-theme-introduction/assets/js/index.js

35 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-07-19 13:37:06 +00:00
// Nav burger animation
document.addEventListener('DOMContentLoaded', function () {
2018-07-19 13:37:06 +00:00
// Get all "navbar-burger" elements
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0)
2018-07-19 13:37:06 +00:00
// 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 () {
2018-07-19 13:37:06 +00:00
// Get the target from the "data-target" attribute
var target = $el.dataset.target
var $target = document.getElementById(target)
2018-07-19 13:37:06 +00:00
// Toggle the class on both the "navbar-burger" and the "navbar-menu"
$el.classList.toggle('is-active')
$target.classList.toggle('is-active')
})
})
2018-07-19 13:37:06 +00:00
}
2018-07-01 08:09:29 +00:00
})
// Modal closer
$('.card').click(function () {
$($(this).attr('data-target')).addClass('is-active')
$('html').addClass('modal-open')
})
$('.modal-close').click(function () {
$($(this).attr('data-target')).removeClass('is-active')
$('html').removeClass('modal-open')
})
$(document).keypress(function (e) {
if (e.which === 0) {
$('.modal.is-active').removeClass('is-active')
$('html').removeClass('modal-open')
}
})