BloomStudio Posted August 29 Share Posted August 29 I have created a site with the mobile menu on desktop. My client would like to be able to close the side menu by simply clicking away from the menu and not have to use the X to close. How can I fix that? Thanks Website: https://bumblebee-blenny-z38d.squarespace.com Password: styledhabitat Link to comment
tuanphan Posted September 2 Share Posted September 2 You mean click anywhere on this part? Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!) Link to comment
BloomStudio Posted September 2 Author Share Posted September 2 Yes that part thank you Link to comment
BloomStudio Posted September 3 Author Share Posted September 3 Sorry, no I mean click anywhere on the website and the menu would close automatically. Is this possible? Link to comment
tuanphan Posted Saturday at 01:52 AM Share Posted Saturday at 01:52 AM On 9/3/2024 at 3:09 PM, BloomStudio said: Sorry, no I mean click anywhere on the website and the menu would close automatically. Is this possible? Try this code to Website Tools > Code Injection > Footer <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script> <script> $(document).ready(() => { document.querySelector('.header-menu').id = 'test'; document.querySelector('.header-display-mobile .header-burger-btn').id = 'test-btn'; function handleMenu(e) { const els = e.path; const menu = els.find(el => el.id === 'test') const btn = els.find(el => el.id === 'test-btn') if (!menu && !btn) { setTimeout(() => { const isOpen = document.querySelector('.js-header-burger-close-title').getAttribute('hidden') === null; if (isOpen) document.querySelector('.header-display-mobile .header-burger-btn').click(); }, 100) } } window.addEventListener('click', handleMenu); }) </script> Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment