From 625b16cbbbc762c5f5571efd31c374355ec088ea Mon Sep 17 00:00:00 2001 From: Dmytro Chernetskyi <78321800+chernetskyi8704@users.noreply.github.com> Date: Sun, 4 Sep 2022 08:03:44 +0300 Subject: [PATCH] Added files (#309) * Added files * Chandge link to css file * Added cursor on menu link * Added the event listener on the menu container to use the event delegation. * Fixed a bug when we can click on whole menu. * Has made refactoring my code and added 3 separate function: toggleActiveMenuItem, renderData, cleanContent, getSelectData --- .../Interactive Side-menu/index.html | 59 ++++ .../Interactive Side-menu/script.js | 98 ++++++ .../Interactive Side-menu/style.css | 303 ++++++++++++++++++ 3 files changed, 460 insertions(+) create mode 100644 submissions/chernetskyi8704/Interactive Side-menu/index.html create mode 100644 submissions/chernetskyi8704/Interactive Side-menu/script.js create mode 100644 submissions/chernetskyi8704/Interactive Side-menu/style.css diff --git a/submissions/chernetskyi8704/Interactive Side-menu/index.html b/submissions/chernetskyi8704/Interactive Side-menu/index.html new file mode 100644 index 0000000000..3a92b211c7 --- /dev/null +++ b/submissions/chernetskyi8704/Interactive Side-menu/index.html @@ -0,0 +1,59 @@ + + + + + + + + Interactive Side-menu + + +
+
+ + +
+

Fusilli

+
+
+ + + Fusilli are a variety of pasta that are formed into corkscrew or + helical shapes. The word fusilli presumably comes from fuso + ("spindle"), as traditionally it is "spun" by pressing and + rolling a small rod over the thin strips of pasta to wind them + around it in a corkscrew shape. + +
+
+
+
+
+ + + diff --git a/submissions/chernetskyi8704/Interactive Side-menu/script.js b/submissions/chernetskyi8704/Interactive Side-menu/script.js new file mode 100644 index 0000000000..c653bca76c --- /dev/null +++ b/submissions/chernetskyi8704/Interactive Side-menu/script.js @@ -0,0 +1,98 @@ +"use strict"; + +const mainContent = document.querySelector(".main__content"); +const menuItem = document.querySelectorAll(".menu__link"); +const menuList = document.querySelector(".menu__list"); +const iconBurger = document.querySelector(".menu__icon-burger"); +const menuBody = document.querySelector(".main__menu"); + +const contentData = [ + { + name: "Fusilli", + image: "img/Fusilli.jpg", + alt: "", + description: + "Fusilli are a variety of pasta that are formed into corkscrew or helical shapes. The word fusilli presumably comes from fuso ('spindle'), as traditionally it is 'spun' by pressing androlling a small rod over the thin strips of pasta to wind them around it in a corkscrew shape.", + }, + { + name: "Casarecce", + image: "img/Casarecce.jpg", + alt: "", + description: + "Originating in Sicily, casarecce is a traditional short pasta, loosely rolled lengthways and slightly twisted. Their twisted shape makes them perfect for holding sauces, whether it’s simple pesto or chunky sauces made from eggplant, ricotta and basil.", + }, + { + name: "Malloreddus", + image: "img/Malloreddus.jpg", + alt: "", + description: + "Malloreddus, also called gnocchetti sardi or ‘little Sardinian gnocchi’ is a typical pasta from Sardinia. Many Italians call it Sardinian gnocchi because of the shape. It really looks like tiny potato gnocchi. But it is actually a pasta made of durum wheat semolina flour, water and salt. However, the same technique to make it is the same as gnocchi.", + }, + { + name: "Macaroni", + image: "img/Macaroni.jpg", + alt: "", + description: + "One of the earliest forms of pasta, macaroni is made from durum wheat and is shaped in short tubes with holes down the middle. Although artisanal brands may be made by hand using traditional methods, commercial varieties are produced using state-of-the-art pasta machines. Other varieties of macaroni include elbow macaroni (short and curved) and macaronicini (small shapes).", + }, + { + name: "Riccioli", + image: "img/Riccioli.jpg", + alt: "", + description: + "A variety of fresh egg pasta that is often associated with pasta makers in the Piemont region of Italy. Very similar in shape to fusilloni, rotini spiral, and rotelle pasta, the Riccioli Pasta is formed into many layers of ridges, spaced closely together that spiral upward. Because of its unique shape, it is good pasta for holding a variety of different pasta sauces.", + }, +]; + +iconBurger.addEventListener("click", (e) => { + document.body.classList.toggle("_lock"); + iconBurger.classList.toggle("_active"); + menuBody.classList.toggle("_active"); +}); + +const getSelectData = (target) => { + const { name, image, alt, description } = contentData[target.id]; + + const template = `

${name}

+
+
+ ${alt} + + ${description} + +
+
`; + + return template; +}; + +const cleanContent = (area) => (area.innerHTML = ""); + +const renderData = function (area, target) { + return area.insertAdjacentHTML("beforeend", getSelectData(target)); +}; + +const toggleActiveMenuItem = (listOfMenuItems, target) => { + listOfMenuItems.forEach((item) => { + item.classList.remove("_activeBtn"); + }); + target.classList.add("_activeBtn"); +}; + +menuList.addEventListener("click", (event) => { + const target = event.target; + + if (iconBurger.classList.contains("_active")) { + document.body.classList.remove("_lock"); + iconBurger.classList.remove("_active"); + menuBody.classList.remove("_active"); + } + + toggleActiveMenuItem(menuItem, target); + cleanContent(mainContent); + renderData(mainContent, target); +}); diff --git a/submissions/chernetskyi8704/Interactive Side-menu/style.css b/submissions/chernetskyi8704/Interactive Side-menu/style.css new file mode 100644 index 0000000000..784e9d738b --- /dev/null +++ b/submissions/chernetskyi8704/Interactive Side-menu/style.css @@ -0,0 +1,303 @@ +/*RESET*/ +* { + padding: 0; + margin: 0; + border: 0; +} +*, +*:before, +*:after { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} +:focus, +:active { + outline: none; +} +a:focus, +a:active { + outline: none; +} +nav, +footer, +header, +aside { + display: block; +} +html, +body { + height: 100%; + width: 100%; + font-size: 100%; + line-height: 1; + font-size: 14px; + -ms-text-size-adjust: 100%; + -moz-text-size-adjust: 100%; + -webkit-text-size-adjust: 100%; +} +input, +button, +textarea { + font-family: inherit; +} +input::-ms-clear { + display: none; +} +button { + cursor: pointer; +} +button::-moz-focus-inner { + padding: 0; + border: 0; +} +a, +a:visited { + text-decoration: none; +} +a:hover { + text-decoration: none; +} +ul li { + list-style: none; +} +img { + vertical-align: top; +} +h1, +h2, +h3, +h4, +h5, +h6 { + font-size: inherit; + font-weight: inherit; +} +/*--------------------*/ +body { + height: 100%; + font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif; + letter-spacing: 1.5px; +} + +body._lock { + overflow: hidden; +} + +.wrapper { + height: 100%; + width: 100%; + display: flex; +} + +.main { + display: flex; + width: 100%; +} + +.main__menu { + flex: 0 0 185px; + padding: 40px 20px 50px 50px; +} + +.menu__list { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} + +.menu__item { + display: flex; + align-items: center; + justify-content: center; + height: 75px; + width: 100%; +} + +.menu__link { + display: flex; + align-items: center; + justify-content: center; + height: 100%; + width: 100%; + font-size: 30px; + padding: 5px; + cursor: pointer; +} + +._activeBtn { + background-color: rgba(248, 204, 184, 0.9); + color: white; +} + +.menu__link:hover { + background-color: rgba(248, 204, 184, 0.9); + color: white; +} + +.main__content { + display: flex; + align-items: center; + justify-content: flex-start; + flex-direction: column; + flex: 1 1 auto; + margin: 20px 30px; + padding: 20px; +} + +.content__name { + font-size: 54px; + width: 100%; + text-align: center; +} + +.content__section { + display: flex; + width: 100%; + flex-direction: row; + align-items: center; + margin-top: 10px; +} + +.section__img-container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + overflow: hidden; +} + +.section__img { + object-fit: contain; + height: 100%; + width: 45%; + margin-bottom: 20px; +} + +.section__description { + text-align: center; + font-size: 31px; + line-height: 38px; + min-width: 50%; + max-height: 100%; + padding-bottom: 40px; +} + +@media (max-width: 1199.98px) { + .section__description { + font-size: 35px; + } + + .content__name { + font-size: 58px; + } + + .menu__link { + font-size: 34px; + } + + .content__name { + font-size: 54px; + } + + .section__img { + width: 65%; + } +} + +@media (max-width: 991.98px) { + .section__img { + width: 90%; + } +} + +@media (max-width: 767.98px) { + .main__menu { + flex: 0 0 140px; + margin-right: 5px; + } + + .section__img-container { + margin-top: 0px; + } + + .section__img { + min-width: 75%; + } + + .menu__icon-burger { + z-index: 5; + display: block; + position: absolute; + top: 20px; + right: 20px; + width: 30px; + height: 18px; + } + + .menu__icon-burger .burger_span, + .menu__icon-burger:before, + .menu__icon-burger:after { + left: 0px; + position: absolute; + height: 10%; + width: 100%; + transition: all 0.4s ease 0s; + background-color: black; + } + + .menu__icon-burger:before, + .menu__icon-burger:after { + content: ""; + } + + .menu__icon-burger:before { + top: 0; + } + + .menu__icon-burger:after { + bottom: 0; + } + + .menu__icon-burger .burger_span { + top: 50%; + transform: scale(1) translate(0px, -50%); + } + + .menu__icon-burger._active .burger_span { + transform: scale(0) translate(0px, -50%); + } + + .menu__icon-burger._active:before { + top: 50%; + transform: rotate(-45deg) translate(0px, -50%); + } + + .menu__icon-burger._active:after { + bottom: 50%; + transform: rotate(45deg) translate(0px, 50%); + } + + .main__menu._active { + left: 0; + } + + .main__menu { + position: fixed; + top: 0; + left: -100%; + width: 55%; + height: 100%; + background-color: rgba(0, 0, 0, 0.9); + padding: 40px 20px 30px 10px; + transition: left 0.6s ease 0s; + color: white; + } +} + +@media (max-width: 575.98px) { + .section__img { + width: 120%; + } +}