jQuery悬浮问题由于z-index [英] jQuery hover problem due to z-index

查看:162
本文介绍了jQuery悬浮问题由于z-index的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用jQuery触发一个元素的悬停事件,但是我使用z-index在元素上方有一个半透明的png。有没有办法告诉jQuery忽略png并触发下面的元素的悬停事件?

解决方案

如果你是使用支持css3的现代浏览器,尝试将此行添加到透明png的css规则:指针事件:无;

它基本上告诉浏览器忽略此元素上的所有鼠标事件。



例如:

  img 
{
指针事件:无;
}

https://developer.mozilla.org/en/css/pointer-events



或者如果您的目标浏览器不支持css3,您可以捕获鼠标事件,然后在基础元素上触发一个新的事件。



例如,如果您的图像ID是#img你的底层元素id是#elem你可以这么做:

  $(#elem)。hover ){
$(#img)。mouseenter(e);
});

根据DOM的设置方式,您可能需要稍等一些,以下是文档 http://api.jquery.com/mouseenter/


I want to trigger a hover event for an element using jQuery, but I have an semi-transparent png positioned over the element using z-index. Is there any way to tell jQuery to ignore the png and trigger the hover event for the element underneath it?

解决方案

If you are using a modern browser that supports css3, try adding this line to the css rule for the transparent png: pointer-events: none;
It basically tells the browser to ignore all mouse events on this element.

For example:

img
{
    pointer-events: none;
}

https://developer.mozilla.org/en/css/pointer-events

Alternatively if your targeted browser does not support css3, you can capture the mouse event and then fire a new one on the underlying element.

for example if your image id is #img and your underlying element id is #elem you may do this:

$("#elem").hover(function(e){
     $("#img").mouseenter(e);
});

You might have to mess with this a little depending on how your DOMs are set up, here's the documentation http://api.jquery.com/mouseenter/

这篇关于jQuery悬浮问题由于z-index的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆