有没有办法将鼠标悬停在jquery中另一个元素z索引下方的元素上?
我有一张地图,分为三部分,地图背景、地图标签和地图部分本身,顺序如下:
地图背景:z-index = 1
地图标签:z-index = 3
地图片段(悬停):z-index = 2
(位于标签下方)
如果使用 jquery 的顶部有一个元素,有没有办法将鼠标悬停在 z-index = 2
上? (即标签)
I have a map split into three parts, the map background, the map labels and the map piece itself the order is as follows:
map background: z-index = 1
map label: z-index = 3
map piece (hover): z-index = 2
(to go under the label)
Is there a way to hover over the piece which is z-index = 2
if there is an element on top of that using jquery? (i.e. the label)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您也可以触发标签上的悬停,或者在所有内容之上创建不可见的 div:
You can either trigger the hover on the label as well, or create invisible divs on top of everything:
编辑:好的,这似乎有效。不确定是否有任何缺点。
http://jsfiddle.net/Sdsax/1/
基本上将标签和片段都放在一个分区。将鼠标悬停在 div 上。由于容器 div 除了绝对定位的元素之外没有任何内容,因此它不会显示。但由于这两个元素都在该 div 内,因此它们会在两个元素上悬停。
编辑2:更新了小提琴。正如您在更新的小提琴中看到的,由于它们确实具有相同的处理程序,因此如果它们重叠,从一个移动到另一个将不会再次触发悬停。
EDIT: Okay, this seems to work. not sure if there are any drawbacks.
http://jsfiddle.net/Sdsax/1/
Basically put both the label and the piece inside of a div. Put the hover on the div. Since the container div has no contents other than the absolutely positioned elements, it won't show. But since both elements are within that div, they hover fires on both.
EDIT 2: Updated fiddle. As you can see in the updated fiddle, since they really have the same handler, if they overlap, moving from one to the other will not fire the hover again.