I’m trying to have my hidden description show over each imageContainer it’s connected to. However no matter which one I point to the description shows somewhere else on the page. Furthermore, I must have messed something up with the loop.Do I need an extra div somewhere? Some images have 2 descriptions that show up when you hover over them instead of 1, and some you get nothing.
document.addEventListener('DOMContentLoaded',function () {
const images=document.querySelectorAll('.imageContainer')
const descriptions=document.querySelectorAll('.hidden');
images.forEach((image, index) => {
image.addEventListener('mouseover', () => {
descriptions[index].style.display = 'block';
});
image.addEventListener('mouseout', () => {
descriptions[index].style.display = 'none';
});
});
});
.imageContainer{
position: relative;
display: inline-block;
width: 100%;
}
.imageContainer:hover ~ .hidden{
position: absolute;
transform: translate(-50%, -50%);
z-index: auto;
color: white;
background: rgba(65, 64, 64, 0.51);
}
<div class="container justify-content-evenly">
<div class="row">
<div class="imageContainer col-md-6">
<img
src="images/Mermaid.png"
class="img-fluid"
alt="mermaid"
id="page1-img"
/>
</div>
<div class="hidden description col-md-6 mb-5">
<div class="appTitle text-start text-decoration-underline" id="app-title">
Mermaid Page
</div>
<p class="text-start p-0">
Now this was the first webpage I ever created. It might not be
responsive, but I find beauty in it's simplicity. It has
significant amount of CSS, very little Javasript, and the
information I used is linked to it's orginal source. It honestly
made me want to learn more about coding.
</p>
<a
class="btn btn-dark text-start text-start border border-white p-3"
href="https://my-first-site-jj.netlify.app/"
target="_blank"
role="button"
id="launch-app"
title="Learn about Memaids"
>Launch App</a
>
</div>
<div class="hidden description col-md-6 mb-5">
<div class="appTitle text-start text-decoration-underline" id="app-title">
World Clock App
</div>
<p class="description text-start p-0">
Check what the time is not only in your area, but in the listed
countries. I implemented moment_timezone and Javascript to give
you the different timezone you see here. Hope you check it out and
enjoy.
</p>
<br />
<a
class="btn btn-dark text-start text-start border border-white mb-5 p-3"
href="https://world-clock-jordanka.netlify.app/"
target="_blank"
title="Check The Time"
role="button"
id="launch-app"
>Launch App</a
>
</div>
<div class="imageContainer col-md-6">
<img
src="images/clock.PNG"
alt="clock app"
class="img-fluid"
id="page1-img"
/>
</div>
<div class="imageContainer col-md-6">
<img
src="images/Weather_App.png"
alt="weather app"
class="img-fluid"
id="page1-img"
/>
</div>
<div class="hidden description col-md-6 mb-5">
<div class="appTitle text-start text-decoration-underline" id="app-title">
Weather App
</div>
<p class="description text-start p-0">
Do you want to know your 5 day forecast? What about in any city
in the world? Just type a city in the search engine and see the
results. This app was made with React and to get this
information I utilized Shecodes Weather API and my own APIkey.
</p>
<br />
<a
class="btn btn-dark text-start text-start border border-white p-3"
href="https://jj-weather-react.netlify.app/"
target="_blank"
title="Check Your Weather"
role="button"
id="launch-app"
>Launch App</a
>
</div>
<div class="hidden description col-md-6 mb-5">
<div class="appTitle text-start text-decoration-underline" id="app-title">
Dictionary App
</div>
<p class="description text-start p-0">
Look up anyword you want, with an old-timey feel, and possiblily have some images for examples. I incorporated two different api keys for this project. I connected the pexel api to the dictionary api so the images would match the researched word.
</p>
<a
class="btn btn-dark text-start text-start border border-white p-3"
href="https://jj-dictionary-app.netlify.app"
target="_blank"
role="button"
id="launch-app"
title="look up words with my Dictionary"
>Launch App</a
>
</div>
<div class="imageContainer col-md-6">
<img
src="images/Dictionay.png"
alt="Dictionay app"
class="img-thumbnail"
id="page1-img"
/>
</div>
<div class="imageContainer col-md-6">
<img
src="images/Marc-landing.png"
alt="landing page about Marc Anthony"
class="img-thumbnail"
id="page1-img"
/>
</div>
<div class="hidden description col-md-6 mb-5">
<div class="appTitle text-start text-decoration-underline" id="app-title">
Marc Anthony Landing Page
</div>
<p class="description text-start p-0">
Do you love Marc Anthony music as much as I do? Or do you simply want to open your ears and mind to some salsa music? Then who better to listen to than the man who's known as the king of Salsa. Click on the launch app to have a listen
</p>
<a
class="btn btn-dark text-start text-start border border-white p-3"
href="http://jj-marcanthony-project.netlify.app"
target="_blank"
role="button"
id="launch-app"
title="Learn about Marc Anthony"
>Launch App</a
>
</div>
<div class="hidden description col-md-6 mb-5">
<div class="appTitle text-start text-decoration-underline" id="app-title">
AI Italian Recipe
</div>
<p class="description text-start p-0">
Ever wanted to make an Italian dish but didn't know where to start? Well take out the guess work and utilize my AI generated Italian Recipe app. Where you can simply type lasagna and it give you a delicious recipe within a minute.
</p>
<a
class="btn btn-dark text-start text-start border border-white p-3"
href="https://italian-food-generator.netlify.app"
target="_blank"
role="button"
id="launch-app"
title="Use AI to get a new Italian recipe"
>Launch App</a
>
</div>
<div class="imageContainer col-md-6">
<img
src="images/AIrecipe.png"
alt="italian recipe generator"
class="img-thumbnail"
id="page1-imgr"
/>
</a>
</div>
</div>