【发布时间】:2014-12-30 21:26:46
【问题描述】:
我有一个<li>'s 列表,旁边有一个图标,悬停时会显示一个包含“测试”信息的叠加层。如下所示:
test1
test2
test3
等等……
html:
<span class="account-info-icon"></span> // icon is the build using image sprites
<div id ="hover-container>
//details about the 'test1','test2'..so on
</div>
js:
$('span.account-info-icon').on("mouseenter", function(event){
$("#hover-container").show();
}).on("mouseout", function(){
$("#hover-container").hide();
});
上面的代码可以很好地在悬停时显示/隐藏 div 容器。但是,我遇到了叠加层的定位问题。我使用 css 来定位叠加层,因此,无论我悬停哪个图标,叠加层始终位于下方。
简而言之,因为我对<div> conatiner 的值进行了硬编码,所以叠加层总是显示在一个地方,并且不会像悬停在图标上那样移动。
下面是用于定位叠加层的 css im。
CSS:
#hover-container{
display: none;
position: relative;
top: -750px;
left: 943px;
padding: 2px 0 0 9px;
}
基本上,我正在尝试根据悬停的流程对齐叠加层。所以当我将鼠标悬停在“test1”图标上时,覆盖应该显示在它旁边。我不确定这是否可以通过 CSS 或 Js 实现。 任何想法表示赞赏!!!!
提前致谢!
【问题讨论】:
标签: javascript jquery html css