Skip to content

SuperZombi/SwipeMenu_JS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwipeMenu_JS

Usage Example | Preview

Usage:

1) Import required files.

<head>
    <link href="https://superzombi.github.io/SwipeMenu_JS/swipe_menu.css" rel="stylesheet">
    <script src="https://superzombi.github.io/SwipeMenu_JS/swipe_menu.js"></script>
</head>

2) Create a div with class swipe-menu.

<div class="swipe-menu">

</div>

3) Inside this div, create an element for the back button.

<div class="swipe-menu">
	<div class="back_button">
		Back
	</div>
</div>

4) Create ul with main menu. You can also create a menu title inside of it and provide links to submenu.

<div class="swipe-menu">
	<div class="back_button">Back</div>

	<ul class="menu">
		<li class="menu_title">
			Menu
		</li>
		<li submenu="language">
			Language
		</li>
		<li submenu="theme">
			Theme
		</li>
	</ul>
</div>

5) Create a submenus.

<div class="swipe-menu">
	...

	<ul class="submenu" name="theme">
		<li class="menu_title">
			Theme:
		</li>
		<li value="light">
			Light
		</li>
		<li value="dark">
			Dark
		</li>
	</ul>
</div>

6) Initialize SwipeMenuJS.

var myMenu = document.getElementById("myMenu")
swipeMenu(myMenu)

If you want the menu to be swiped from the right, specify this.

var myMenu = document.getElementById("myMenu")
swipeMenu(myMenu, 'right')

Right swipe example | Preview

7) Set the default value.

myMenu.init('language', 'en')

You can also track the value change and call the callback.

myMenu.init('theme', 'dark', onchange=(target, old_element)=>{
    document.body.classList.remove(old_element.getAttribute("value"))
    document.body.classList.add(target.getAttribute("value"))
})

Full Example | Preview

8) You can also update the value.

myMenu.update('language', 'ru')

9) If you need, you can close all submenus.

myMenu.exitAllSubMenus()

10) To insert a link, you must specify the href attribute.

<li href="#account">
	Account
</li>

You can also add target="_blank".

11) To add a selected value for an element that does not have a submenu, specify a name for it.

<li name="account">
	Account
</li>

12) To display selected values on the right, specify the class space-between for swipe-menu.

<div class="swipe-menu space-between">

</div>

💲Support the project

Donatello
Donation Alerts

(But now it's better to email me and I'll send you the details)