【发布时间】:2018-09-09 02:05:34
【问题描述】:
挑战如下:
我在一个 HTML 文件中有两个相互叠加的 div。顶部 div 使用 CSS 大部分是透明的,底部 div 有一个图像作为其背景。在 mouseenter 上,我希望顶部 div 消失,而在 mouseleave 上,我希望顶部 div 回来。
$(document).ready(function() {
$('.dimmer').on('mouseenter', event => {
$(this).hide();
}).on('mouseleave', event => {
$(this).show();
});
});
.experience {
background: url("cmu-110.png") no-repeat center;
height: 110px;
width: 110px;
z-index: 2;
}
.dimmer {
background: rgba(238, 238, 238, .25);
position: relative;
top: -128px;
z-index: 3;
}
<div>
<div class="experience"></div>
<div class="dimmer"></div>
</div>
上面的jquery代码sn-p在一个单独的文件中,在html的头部调用。
<head>
<!--- Some head stuff like title, meta, calling css in separate file, etc --->
<!--jquery-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="interaction.js"></script>
</head>
完全透明:我是 jquery 新手,第一次尝试使用它。尽管完成了完整的 codecademy jquery 教程,阅读了 w3C 学校教程,搜索了其他 stackoverflow 帖子,并且花费了超过合理的时间,但我似乎无法让它工作——可能是由于一个愚蠢的错误。
感谢您的帮助!
【问题讨论】:
标签: javascript jquery css mouseenter mouseleave