html - 将鼠标悬停在链接中时如何显示图像?

标签 html css hover

<分区>


想改进这个问题吗? 通过 editing this post 添加细节并澄清问题.

关闭 3 年前

我试图在将鼠标悬停在链接中时显示隐藏的部分,但我做不到。

<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 并复制到其他链接和图像。

This is how website looks without hover

And this is what I'm trying to make

最佳答案

我有一个解决方案给你。我已经把它贴在这里了。希望对您有所帮助。

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/

上一篇:css - 仅为外部组件启用滚动条

下一篇:html - 如何在 TestCafé 的输入标签内上传文件

相关文章:

html - 是什么让 <button> 元素上的文本垂直居中?

html - html和CSS中的垂直流布局

javascript - AngularJs 上的加载 url 未检测到 onload 事件

html - 将按钮与文本区域垂直对齐

Javascript 菜单样式——循环内循环

html - 悬停时图像翻转只是反射(reflect)图像,而不是实际翻转

javascript - 在js/jquery中动态添加ID

jquery - Bootstrap v4 导航栏错误?

javascript - 在样式表中声明后删除元素的悬停属性

html - 如何使用悬停叠加图像格式化文本