jQuery /hover()/.mousemove() 优化问题
我正在研究一个基本的模式示例,其中只要用户将鼠标悬停在某个部分上,模式就会跟随鼠标光标。
我遇到的问题是,当从左向右移动时,模式会显着滞后,并且如果用户将鼠标移出特定部分,还会触发 fadeOut() 设置。
从右到左,无缝工作。
在小提琴中,您可以观察到将鼠标从上到下移动到
如果有任何重复的问题或你们都知道的相关文章,请给我指出正确的方向。到目前为止,我的搜索仅供参考,但尚未解决这个具体问题。
这是我的小提琴。
谢谢大家,一如既往地热烈欢迎专业人士的建议。
肯
I'm working on a basic modal example in which the modal would follow the mouse cursor as long as the user was hovering over a certain section.
The issue I'm having is, when going from left to right, the modal lags significantly, as well as triggers the fadeOut() set if the user were to mouse out of the specific section.
Right to left, works seamlessly.
In the fiddle, you can observe the lagginess when moving the mouse over the <nav>
from top to bottom, as well as notice the solid performance from bottom to top.
If there are any duplicate questions or related articles that you all know of, please point me in the right direction. My searches thus far have been informational but have not adressed this specific issue.
Here is my fiddle.
Thank you all, as always pro advice is warmly welcomed.
Ken
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是,当您添加模态元素时,jquery 会触发 onmouseout 事件,它会获得“焦点”,并且悬停事件不会在您的导航元素上触发。
我更改了您的示例,使其现在工作得更好,请查看此处
The issue is that jquery fires onmouseout event when you add the modal element it gets "focus" and hover events are not firing on your nav element.
I altered your example so that it is wokring much better now, check it out here
哦,太棒了,经典的例子!问题在于,一旦您触摸
section#coming-soon
,jQuery 就会认为您已将鼠标移出,因此它显然会运行fadeOut
...一种克服方法这是为了将
section#coming-soon
放入nav
中,这样脚本仍会认为您位于section#coming-soon
内code>,即使您将鼠标悬停在其上:示例如下:http://jsfiddle.net/gcJuz/1/
Oh awesome, classic example! The problem is that the jQuery thinks you've moused-out once you touch the
section#coming-soon
, so it obviously runs thefadeOut
...One way to overcome this is to put the
section#coming-soon
inside thenav
, that way the script will still think you're inside thesection#coming-soon
, even if you hover over it:Example here: http://jsfiddle.net/gcJuz/1/
只需提供一些建议即可提供帮助。
Just a few recommendations to help out.