<分区>
我试图在将鼠标悬停在链接中时显示隐藏的部分,但我做不到。
<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>
我想在悬停#fromdesigner 时显示#preview-01 并复制到其他链接和图像。
最佳答案
我有一个解决方案给你。我已经把它贴在这里了。希望对您有所帮助。
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>
关于html - 将鼠标悬停在链接中时如何显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57020316/