-1

I'm trying to show a hidden section when hover in a link, but I can't make it.

<section class="projects">
    <section id="project-list">
        <p id="america-regular-list"><a id="fromdesigner" href="">From Designer to Designer</a></p>
        <p id="america-regular-list"><a href="">Wasted Time</a></p>
        <p id="america-regular-list"><a href="">Thirty Logos</a></p>
        <p id="america-regular-list"><a href="">Aesthetic Posters</a></p>
    </section>
</section>
<section class="preview">
    <section id="preview-01"><img src="img/preview-project-01.jpg"/></section>
</section>

I want to show #preview-01 when hover #fromdesigner and replicate to the other links and images.

This is how website looks without hover

And this is what I'm trying to make

Meraj al Maksud
  • 1,440
  • 2
  • 22
  • 35

3 Answers3

2

I've a solution for you. I've posted it here. Hope it will be helpful.

function imgShow1() {
  document.getElementById('preview-01-img').style.opacity = 1;
}

function imgHide1() {
  document.getElementById('preview-01-img').style.opacity = 0;
}

function imgShow2() {
  document.getElementById('preview-02-img').style.opacity = 1;
}

function imgHide2() {
  document.getElementById('preview-02-img').style.opacity = 0;
}

function imgShow3() {
  document.getElementById('preview-03-img').style.opacity = 1;
}

function imgHide3() {
  document.getElementById('preview-03-img').style.opacity = 0;
}

function imgShow4() {
  document.getElementById('preview-04-img').style.opacity = 1;
}

function imgHide4() {
  document.getElementById('preview-04-img').style.opacity = 0;
}
.preview img {
  height: 10vw;
  width: 20vw;
  object-fit: cover;
  opacity: 0;
  transition: all .33s ease-in-out;
}

.preview section {
  display: inline-block;
}
<section class="projects">
    <section id="project-list">
        <p id="america-regular-list"><a id="fromdesigner" href="" onmouseover="imgShow1()" onmouseleave="imgHide1()">From Designer to Designer</a></p>
        <p id="america-regular-list"><a href="" onmouseover="imgShow2()" onmouseleave="imgHide2()">Wasted Time</a></p>
        <p id="america-regular-list"><a href="" onmouseover="imgShow3()" onmouseleave="imgHide3()">Thirty Logos</a></p>
        <p id="america-regular-list"><a href="" onmouseover="imgShow4()" onmouseleave="imgHide4()">Aesthetic Posters</a></p>
    </section>
</section>
<section class="preview">
    <section id="preview-01"><img id="preview-01-img" src="https://i.imgur.com/J67Ukc8.jpg"/>
    <section id="preview-02"><img id="preview-02-img" src="https://i.imgur.com/J67Ukc8.jpg"/>
    <section id="preview-03"><img id="preview-03-img" src="https://i.imgur.com/J67Ukc8.jpg"/>
    <section id="preview-04"><img id="preview-04-img" src="https://i.imgur.com/J67Ukc8.jpg"/></section>
</section>
Showrin Barua
  • 1,659
  • 1
  • 8
  • 21
1

Actually, in css you cant do hover effect unless if you target child or sibling, i have edit your html to be like the next snippet, its not the best solution, and not responsive, but at least without javascript

#projects{
  position: relative;
}

p{
  width: 50%;
}
.preview{
  display: none;
}
img{
  width: 50%;
  right: 0;
  position: absolute;
  top: 15px
}
#america-regular-list1:hover ~ .preview{
  display: block;
}
<section class="projects">
    <section id="project-list">
        <p id="america-regular-list1"><a id="fromdesigner" href="">From Designer to Designer</a></p>
        <p id="america-regular-list"><a href="">Wasted Time</a></p>
        <p id="america-regular-list"><a href="">Thirty Logos</a></p>
        <p id="america-regular-list"><a href="">Aesthetic Posters</a></p>
      
      <div class="preview"><img src="https://www.jamierubin.net/wp/wp-content/uploads/2015/12/Blog-Header-Burke.jpg"/></div>
    </section>
</section>

you can achieve what u want easily in jQuery or vanila JS.

my note : don't repeat ID in your html, its not good practice.

0

I don't quite understand your problem here. But you could embed each image under each link.

    <section id="project-list">
        <p id="america-regular-list"><a id="fromdesigner" href="">From Designer to Designer</a><img src="img/preview-project-01.jpg" id="hello"/></p>
        <p id="america-regular-list"><a href="">Wasted Time</a><img src="img/preview-project-01.jpg" /></p>
        <p id="america-regular-list"><a href="">Thirty Logos</a><img src="img/preview-project-01.jpg"/></p>
        <p id="america-regular-list"><a href="">Aesthetic Posters</a><img src="img/preview-project-01.jpg"/></p>
    </section>
</section>

In Css:

img{
display: none;
}
a#fromdesigner:hover #hello{
display: inline-block;
}

Hope it helps!!

Khay Leng
  • 323
  • 2
  • 7