Created
January 16, 2019 11:25
-
-
Save XIOLog/d8cb85d95621ee2dabbc7362e5b200a6 to your computer and use it in GitHub Desktop.
Небольшая менюшка на JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Container() { | |
| this.htmlCode = ''; | |
| } | |
| Container.prototype.render = function() { | |
| return this.htmlCode; | |
| }; | |
| Container.prototype.remove = function() { | |
| document.getElementById('menu').remove(); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html lang="ru"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" | |
| content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
| <title>Document</title> | |
| <script> | |
| window.onload = function() { | |
| const topMenu = new Menu('menu', 'm-block', [ | |
| new MenuItem('/', 'Главная'), | |
| new MenuItem('/catalog', 'Каталог'), | |
| new MenuItem('/stocks', 'Акции'), | |
| new MenuItem('/about', 'О нас'), | |
| new MenuItem('/contacts', 'Контакты'), | |
| new Submenu('Поддержка', 'sMenu', 'sm-block', [ | |
| new MenuItem('/', 'Главная'), | |
| new MenuItem('/catalog', 'Каталог'), | |
| new MenuItem('/stocks', 'Акции'), | |
| new MenuItem('/about', 'О нас'), | |
| new MenuItem('/contacts', 'Контакты'), | |
| ]) | |
| ]); | |
| let menuApp = document.getElementById('mainMenu'); | |
| menuApp.innerHTML = topMenu.render(); | |
| document.getElementById('removeMenu').addEventListener('click', function() { | |
| topMenu.remove(); | |
| }); | |
| }; | |
| </script> | |
| </head> | |
| <body> | |
| <div id="mainMenu"></div> | |
| <button id="removeMenu">Удалить меню</button> | |
| <script src="js/Container.js"></script> | |
| <script src="js/Menu.js"></script> | |
| <script src="js/MenuItem.js"></script> | |
| <script src="js/Submenu.js"></script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment