如何使Internet Explorer模拟指针事件:无?

我正在通过在图表上显示一个渐变PNG来处理一个项目,在这个项目中我们正在增强highcharts。 我们正在使用CSS pointer-events:none; 允许用户与图表进行交互,尽pipe顶部有一个div。 IE不识别pointer-events:none; ,所以IE上的用户既不能有增强的图表devise,也不能与图表交互。 我正在寻找一种方法来让IE浏览器允许鼠标事件(特定的hover事件),通过一个div到它下面的元素。

你可以在这里看到我们正在使用的模型: http : //jsfiddle.net/PFKEM/2/

有没有办法让IE做类似 pointer events:none; ,鼠标事件是通过元素传递给元素的呢?

希望这可以帮助 :)

http://www.vinylfox.com/forwarding-mouse-events-through-layers/

你也可以尝试一个JavaScript解决scheme:

http://jsbin.com/uhuto

Internet Explorer可识别指针事件:无 ,但仅用于SVG元素,因为指针事件仅在W3C规范( http://www.w3.org/TR/SVG/interact.html#PointerEventsProperty )中为SVG元素指定。

你可以用这样的东西试试

CSS:

 #tryToClickMe{ pointer-events: none; width: 400px; height: 400px; background-color: red; } 

HTML:

 <svg id="tryToClickMe"></svg> 

这工作在IE9和IE10(我testing了它)。 如果您还没有使用SVG元素,那么将SVG中的现有元素封装起来是可行的。 jQuery库提供了一个包装方法( http://api.jquery.com/wrap/ )。

有一个很好的德国文章,已经打破了指针事件属性的特点: http : //www.bennyn.de/programmierung/html/unterschiedliche-implementierungen-der-eigenschaft-pointer-events.html – 你会find(在谷歌翻译的帮助下)更多信息。

希望我能帮上忙

class尼

PS如果要访问覆盖和底层对象,则可以使用IE中的document.msElementsFromPoint方法( http://msdn.microsoft.com/de-de/library/windows/apps/hh465811.aspx )。 它会给你一个数组中给定点的所有图层。

刚刚花了两天研究IE10项目(IE10不支持指针事件:无CSS属性,MS投票撤回规范,因为可能的点击劫持问题)。 解决方法是在SVG中使用INLINED SVG标记并设置指针事件。 我一直试图使用SVG src的IMG标签,或者将背景图像设置为SVG文件的DIV(我使用pointer-events =“none”),甚至是SVG数据,对我来说,让它在一个单独的元素中精确地需要未实现的指针事件CSS属性。

所以你需要这样一个简单的SVG:首先一些CSS例如:

  .squareBottomRight { width: 50px; height: 50px; position: absolute; bottom: 0; right: 0; } 

然后在HTML中:

  <svg class="squareBottomRight" xmlns="http://www.w3.org/2000/svg" pointer-events="none"> <rect id="test2_rect" x="0" y="0" width="50" height="50" fill="blue"/> </svg> 

参考: https : //bug-45467-attachments.webkit.org/attachment.cgi?id = 67050

这是另一个解决scheme,用5行代码很容易实现:

  1. 捕获顶部元素(要closures指针事件的元素)的“mousedown”事件。
  2. 在“mousedown”隐藏顶部元素。
  3. 使用“document.elementFromPoint()”来获取底层元素。
  4. 取消隐藏顶部元素。
  5. 执行底层元素的所需事件。

例:

  //This is an IE fix because pointer-events does not work in IE $(document).on('mousedown', '.TopElement', function (e) { $(this).hide(); var BottomElement = document.elementFromPoint(e.clientX, e.clientY); $(this).show(); $(BottomElement).mousedown(); //Manually fire the event for desired underlying element return false; }); 
 $.fn.passThrough = function (target) { var $target = $(target); return this.each(function () { var style = this.style; if ('pointerEvents' in style) { style.pointerEvents = style.userSelect = style.touchCallout = 'none'; } else { $(this).on('click tap mousedown mouseup mouseenter mouseleave', function (e) { $target.each(function() { var rect = this.getBoundingClientRect(); if (e.pageX > rect.left && e.pageX < rect.right && e.pageY > rect.top && e.pageY < rect.bottom) $(this).trigger(e.type); }); }); } }); }; 

http://jsfiddle.net/yckart/BQw4U/

 $('.overlay').passThrough('.box'); $('.box').click(function(){ $(this).toggleClass('active'); }); 

CSS:

 #red_silk { width:100%; background: url('../img/red_silk.png') no-repeat center top; height:393px; z-index: 2; position: absolute; pointer-events: none; } 

旧的HTML:

 <div id="red_silk"></div> 

新的HTML:

 <svg id="red_silk"></svg> 

添加下面的CSS将禁用ms指针。

 #container{ -ms-touch-action: none; }