Unverified

Name

Apple-Mobile-Menu

About

This is how to add a Mobile Menu like the Apple Website with the use of stacked containers with IDs to control navigation and what is shown/hidden. This should be added to HTML.

Language

HTML

Rating

Voted: 1 by 1 user(s)

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

25/02/2024

Important Note

This snippet has the following status:

Unverified

This snippet has not been verified, use with caution and at your own risk. See details provided by author in sidebar and click below to find out more.

Apple-Mobile-Menu

 
                    
1<style>
2 /* Apply styles to any element whose ID starts with 'Menu' */
3 [id^='Menu'] {
4 opacity: 0; /* Start invisible */
5 display: none; /* Ensure it doesn't take up space when not visible */
6 position: absolute; /* Use absolute positioning */
7 top: 0; /* Adjust top as necessary */
8 left: 0; /* Adjust left as necessary */
9 z-index: 9999; /* Ensure it's above other content */
10 }
11 
12 /* Apply pointer cursor to any element whose ID starts with 'Icon' or 'Link' */
13 [id^='Icon'], [id^='Link'] {
14 cursor: pointer;
15 }
16</style>
17 
18<script>
19document.addEventListener("DOMContentLoaded", function() {
20 // Function to toggle visibility for a specific element by ID
21 function toggleVisibility(elementId, show) {
22 var element = document.getElementById(elementId);
23 if (element) {
24 element.style.display = show ? 'flex' : 'none';
25 element.style.opacity = show ? '1' : '0';
26 }
27 }
28 
29 // Function to close all elements starting with 'Menu'
30 function closeAllMenus() {
31 document.querySelectorAll("[id^='Menu']").forEach(function(menu) {
32 menu.style.display = 'none';
33 menu.style.opacity = '0';
34 });
35 }
36 
37 // Show Menu_main when Link_open is clicked
38 document.getElementById('Link_open').addEventListener('click', function() {
39 toggleVisibility('Menu_main', true);
40 });
41 
42 // Adapted to handle any ID beginning with Link_close_all to close all menus
43 document.querySelectorAll("[id^='Link_close_all']").forEach(function(btn) {
44 btn.addEventListener('click', function() {
45 closeAllMenus();
46 });
47 });
48 
49 // Show Menu_ipad when Link_open_ipad is clicked
50 document.getElementById('Link_open_ipad').addEventListener('click', function() {
51 toggleVisibility('Menu_ipad', true);
52 });
53 
54 // Show Menu_iphone when Link_open_iphone is clicked
55 document.getElementById('Link_open_iphone').addEventListener('click', function() {
56 toggleVisibility('Menu_iphone', true);
57 });
58 
59 // Setup for any click on IDs starting with Link_close_sub to show only Menu_main
60 document.querySelectorAll("[id^='Link_close_sub']").forEach(function(link) {
61 link.addEventListener('click', function() {
62 closeAllMenus(); // First, close all menus
63 toggleVisibility('Menu_main', true); // Then, show Menu_main
64 });
65 });
66});
67</script>

1

Related Snippets

Please see some snippets below related to this snippet..

General

Unverified

0

Highlight Text Background

Added: 1 month ago

Last Updated: 1 month ago

Highlight and control the colour background for text.

General

AI Verified

0

Cerrar sesion - cliente

Added: 6 months ago

Last Updated: 6 months ago

General

AI Verified

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

32

Remove Unused Javascript

Added: 1 year ago

Last Updated: 3 days ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 2 weeks ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 8 months ago

Last Updated: 1 month ago

This can be used for any WordPress Builder to aid working with CSS Grids.