Create an Accordion Menu in 15 minutes with JavaScript

preview_player
Показать описание
In this project we Create an Accordion Menu in 15 minutes with JavaScript.

Рекомендации по теме
Комментарии
Автор

man.. your way of explaining is so good. u should make more videos like this!

anushrestha
Автор

This is what I call a perfect simple explanation in 15 minutes. Awesome video John! Subscribed.

dj-
Автор

This tutorial is awesome. You explained everything really clearly, and the code is great as well. Not too much, just enough. Love it

fs
Автор

Amazing video; Every other accordion tutorial just made a box appear under the accordion. You on the other hand, expanded the accordion box which is what I wanted!

bobbysmurf
Автор

This is the perfect solution I've been looking for... Thank you so much for this video!

thedeveloperroli
Автор

very great tutorial.. waiting for more javaScript projects.

romelmahmud
Автор

<body>
<div class="accordion">
<div class="accordion-item">
<h2 class="accordion-title"> This is a testing question</h2>
<p class = "accordion-answer">

</p>
</div>
<div class="accordion-item">
<h2 class="accordion-title"> This is a testing question</h2>
<p class = "accordion-answer">

</p>
</div>
<div class="accordion-item">
<h2 class="accordion-title"> This is a testing question</h2>
<p class = "accordion-answer">

</p>
</div>
</div>
<script src="script.js"></script>
</body>

HTML

*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Raleway", sans-serif;
font-weight: 400;
}

body {
background-color: #082d52;
}

.accordion {
max-width: 1200px;
margin: 0 auto;
padding: 50px;
}

.accordion-item {
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
background-color: white;
}

.accordion-title {
display: flex;
align-items: center;
cursor: pointer;
}

.accordion-title::after {
content: "+";
font-size: 40px;
margin-left: auto;
}

.active-header::after {
content: "-";
}

.accordion-answer {
max-height: 0;
overflow: hidden;
transition: 1000ms ease max-height;


CSS


const accordionTitles =

=> {
accordionTitle.addEventListener("click", () => {
const height =
console.log(height);

if {
= `${height}px`;
} else {
= "0px";
}
});
});

JavaScript

bobbysmurf
Автор

There’s one problem actually with this approach. If you keep your accordion tab opened and start resizing the window, it’ll be overflowed since the scroll height stays all the time the same

advance
Автор

Hi John, Great video and really explained. Any tips on how we could extend this slightly to only allow one accordion item to be open at a time?

andybeable
Автор

Is it just me or is the font extremely small in this video? Seems like the content is good, but I can barely see the code.

LuckySampson
Автор

Hey, cool video! As a beginner I find your content quite helpful!

I did everyting you showed step by step. HTML and CSS went smoothly. However, I couldn't make js worked. My code was:

const accordionTitles=

=> {
accordionTitle.addEventlistener("click", () => {
const height =
console.log(height);


= '${height}px';

} else {
= "0px";
}
});
});


It did not work. What was the mistake? And, is there any programme for debugging js codes? Thanks in advance!

leventerenturk
Автор

The tutorial went really smoothly but my if else statement just doesn't seem to be working. When I click on the titles the + changes to a - and console log prints out the scroll height.. I've tripled checked my code against yours but I just can't seem to make it work. Any help, please?

const accordionTitles =

=> {
accordionTitle.addEventListener("click", () => {
const height =
console.log(height);

if {
= '$(height)px';
} else { = "0px";
}

})
})

denhamk
visit shbcf.ru