简体   繁体   English

jquery hover仅适用于click事件?

[英]jquery hover only works on click event?

i have this little jquery code running on jquery 1.10.1, what i want to do is quite basically console log on hover events on hovering over li class dash_item, but it only works when i click the item, not on hover 我在jquery 1.10.1上运行了这个小jquery代码,我想要做的基本上是控制台登录悬停在li class dash_item上的悬停事件,但它只在我点击项目时有效,而不是在悬停时

CODE: 码:

$(document).ready(function(){
    $('.dash_item').on({

       mouseenter: function(){
        console.log("im here");
      },

      mouseleave: function(){
        console.log("im out");
      }
    });
});

the jsfiddle is here http://jsfiddle.net/JQAw3/ jsfiddle在这里http://jsfiddle.net/JQAw3/

Seems to be a Google Chrome bug that can happen when you have a website open for a long time, including the Dev Tools. 似乎是当您长时间打开网站时可能发生的Google Chrome错误,包括开发工具。

I had the same problems, tried everything I could. 我遇到了同样的问题,尽我所能。

In the end, a simple browser restart helped. 最后,简单的浏览器重启有所帮助。

Maybe it's also enough if you simply open the website in another tab. 如果你只是在另一个标签中打开网站,也许就够了。

Edit 2015-06-15: I encounter this problem every time I'm working on mouseenter and mouseleave in Chrome. 编辑2015-06-15:每次我在Chrome中使用mouseentermouseleave都会遇到这个问题。 For me, it's definitely enough to just close the tab and open the website in another. 对我来说,只需关闭标签并在另一个网站中打开网站就足够了。

You can try the jQuery hover() function. 您可以尝试jQuery hover()函数。 It takes a handlerIn and handlerOut. 它需要一个handlerIn和handlerOut。

works fine with hover 悬停时工作正常

http://jsfiddle.net/blackjim/JQAw3/4/ http://jsfiddle.net/blackjim/JQAw3/4/

$('.dash_item').hover(
    function () {
        console.log("im here");
    },
    function () {
        console.log("im out");
    }
);

Leaving this here in case anyone else stumbles across this. 离开这里以防万一其他人偶然发现了这一点。 In early 2015 this is still a 'feature' in chrome/chromium where if the page is being viewed as a file (NOT served from a webserver) the mouse position events like mouseenter , mouseleave , mouseover , etc do not fire. 在2015年初,这仍然是铬/铬的“特征”,如果页面被视为文件(不是从网络服务器提供),鼠标位置事件如mouseentermouseleavemouseover等不会触发。 Don't know if that was OP's issue but was mine when I stumbled across this. 不知道这是OP的问题,但当我偶然发现这个问题时,我的问题就是我的问题。

No it doesn't - same problems with hover as mouseenter 不,它没有 - 与鼠标中心悬停相同的问题

I have had developer tools open for some time 我有一段时间打开开发人员工具

Opened the page in firefox and it worked 在firefox中打开页面,它工作正常

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

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