简体   繁体   English

调整窗口大小时,Chrome中触发了Mouseenter事件

[英]Mouseenter event triggered in chrome when resizing window

Very strange behaviour in Google Chrome ! Google Chrome浏览器中的行为非常奇怪!

I've got a grid of div , and on each of then, I add an eventListenner for mouseenter event. 我有一个网格div ,并在每个然后,我添加eventListenner为mouseenter事件。 In my demo code, when the event is triggered the div get opacity:0.2 . 在我的演示代码中,当事件触发时,div获取opacity:0.2

$(".target_div_class").on("mouseenter",  [my action ...])

Well, it's work's on every browser except in Google Chrome. 嗯,除了Google Chrome浏览器外,其他浏览器都可以使用。

To reproduce the strange behaviour in chrome, go to my codepen demo page place the mouse pointer in front of the grid and start to resize the main browser windows quickly, you will see that some of the divs get opacity changed even if there is not mouse roll-over ! 要重现chrome中的异常行为, 请转到我的codepen演示页 ,将鼠标指针放在网格的前面,并开始快速调整主浏览器窗口的大小,即使没有鼠标,您也会发现某些div的不透明度已更改滚下 !

what I'm doing wrong, is an special jquery event that Chrome doesn't like ? 我做错了,是Chrome不喜欢的特殊jquery事件吗?

thank's 谢谢

larry 拉里

edit -1- 编辑-1-

I think I understand why some div receive the event. 我想我理解为什么有些div接收该事件。

It seem's that, when I click on a border (left or right) of the browser, Chrome keep a trace of the mouse position X and Y. 看来,当我单击浏览器的边框(左侧或右侧)时,Chrome会保留鼠标位置X和Y的痕迹。

Then when slowly expand the browser width, any div that under this "start mouse position" receive the event. 然后,当缓慢扩展浏览器宽度时,此“开始鼠标位置”下的任何div都会接收到该事件。 It is really simple to reproduce when first the browser width is thin, and then slowly expand it, if I take a pen and place it at the mouse start position before resize, It's clear. 首先缩小浏览器的宽度,然后慢慢扩展它,如果我用钢笔将其放到鼠标开始的位置,然后再调整大小,这很简单,这很清楚。 very very strange. 非常非常奇怪

edit -2- 编辑-2-

This behaviour is only on a OS windows 8 , I've just test it on a Mac , and there is not problems ! 此行为仅在Windows 8操作系统上 ,我只是在Mac上进行过测试,没有问题!

Well, I've been testing this behaviour on a couple of sites, like this one : https://devart.withgoogle.com/ 好吧,我已经在几个站点上测试了这种行为,例如: https : //devart.withgoogle.com/

made by Google professional I suppose, and the strange behaviour occurs again, I'll try to find how to contact Google Chrome team ... 我猜想是由Google专业人士做出的,并且再次发生了这种奇怪的行为,我将尝试查找如何与Google Chrome小组联系...

I do not believe that mouseenter/mouseleave is fully supported by chrome. 我认为chrome无法完全支持mouseenter / mouseleave。 Chrome only simulates those functions, unlike in IE. 与IE中不同,Chrome仅模拟这些功能。

But, the problem only occurs when someone tries to re-size the window faster than the browser's edge actually moves and the mouse goes into the page momentarily. 但是,仅当有人尝试以比浏览器边缘实际移动更快的速度调整窗口大小并且鼠标瞬间进入页面时,才会出现问题。 So, its not that unreasonable a behavior. 因此,它不是一个不合理的行为。 You could always try to fix it with a 您随时可以尝试使用

$(window).resize(function() {
    //some code to reset opacity
});

See if this helps 看看是否有帮助

$(".target_div_class").on("mouseenter", function(){
 event.stopPropagation();
   //your code
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM