有没有办法解雇忽略z-index的事件? [英] Is there a way to fire over events ignoring z-index?

查看:73
本文介绍了有没有办法解雇忽略z-index的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这样的话:

有没有办法在BOTH div上触发鼠标悬停事件?

Is there a way to fire the mouseover events on BOTH divs?

编辑:对不起所有..我试图简化这个问题所以很清楚要理解,我忘了提到我有超过100个这样的div,所以可能这些解决方案不起作用。我要看看我是否可以对它们进行调整。非常感谢大家。

Sorry all .. I tried to simplfy the problem so it was clear to understand and I forgot to mention I have more than 100 divs like that so probably those solutions don't work. I'm going to see if I can adpat them. Many thanks everybody anyway.

推荐答案

我在这里用JSFiddle编写了一个工作示例:

I put together a working example here with JSFiddle:

http://jsfiddle.net/gfosco/CU5YT/

它类似于madeinstefanos的答案,但具体到你的例子..

It's similar to madeinstefanos answer, but specific to your example..

var mouseX = 0;
var mouseY = 0;
var front = 0;
var back = 0;

function log(text) {
    $("#log").append(text + '<BR>');
}

function mouseWithin(selector) {
  var pos = $(selector).position();
  var top = pos.top;
  var left = pos.left;
  var height = $(selector).height();
  var width = $(selector).width();

  if (mouseX >= left && mouseY >= top && mouseX <= left + width 
                     && mouseY <= top + height) {
    return true;
  }
  return false;
}

$(document).bind('mousemove', function(e) {
    mouseX = e.pageX;
    mouseY = e.pageY;
    if (front == 1 && !mouseWithin("#front")) {
            front = 0;
            log('Front Leave');
    }
    if (back == 1 && !mouseWithin("#back")) {
            back = 0;
            log('Back Leave');
    }    
    if (front === 0 && mouseWithin("#front")) {     
            front = 1;
            log('Front Hover');
    }
    if (back === 0 && mouseWithin("#back")) { 
            back = 1;
            log('Back Hover');
    }        

});

这篇关于有没有办法解雇忽略z-index的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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