Files
think-greaterchiangmai/think.greaterchiangmai.com/public/js/hamburger-menu.js
2025-11-11 14:55:29 +07:00

64 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*==============================================================
pull menu
==============================================================*/
function bindEvent(el, eventName, eventHandler) {
if (el.addEventListener) {
el.addEventListener(eventName, eventHandler, false);
} else if (el.attachEvent) {
el.attachEvent('on' + eventName, eventHandler);
}
}
(function () {
var bodyEl = document.body,
//content = document.querySelector( '.content-wrap' ),
openbtn = document.getElementById('open-button'),
closebtn = document.getElementById('close-button'),
isOpen = false;
function init() {
initEvents();
}
function initEvents() {
if (openbtn) {
bindEvent(openbtn, 'click', toggleMenu);
}
//openbtn.addEventListener( 'click', toggleMenu );
if (closebtn) {
bindEvent(closebtn, 'click', toggleMenu);
//closebtn.addEventListener( 'click', toggleMenu );
}
// close the menu element if the target it´s not the menu element or one of its descendants..
}
function toggleMenu() {
if (isOpen) {
classie.remove(bodyEl, 'show-menu');
if ( $( ".full-width-pull-menu" ).length ) {
classie.remove(bodyEl, 'overflow-hidden');
classie.remove(bodyEl, 'position-fixed');
}
}
else {
classie.add(bodyEl, 'show-menu');
if ( $( ".full-width-pull-menu" ).length ) {
classie.add(bodyEl, 'overflow-hidden');
classie.add(bodyEl, 'position-fixed');
}
}
isOpen = !isOpen;
}
init();
})();