鼠标悬停并mouseout连续触发事件?
我有一个嵌套 div,我想在鼠标悬停时隐藏它,并在鼠标移出时显示它。
但是,当我尝试这样做时,事件会不断触发。
代码很长,所以更详细,例如 请查看小提琴@ http://jsfiddle.net/jWbZy/16/
I have a nest div that I want to hide on mouse over, and show on mouse out.
However, when I try to do that, the events get triggered continously.
The code is quite long so, for more detailed e.g.
Please check out the fiddle @ http://jsfiddle.net/jWbZy/16/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一种方法:
在轮播面板周围添加一个包装器(我猜这就是 cp 代表的意思):
使用以下样式:
并隐藏/显示其子元素:
此处的工作示例:http://jsfiddle.net/Kxvuk/
Here's a way to do it:
Add a wrapper around your carousel panel (i guess that's what cp stands for):
With the folowing style:
And hide/show its child elements:
Working example here: http://jsfiddle.net/Kxvuk/
这是因为当您隐藏该元素时,当光标不再位于该元素上时也会触发 mouseout 事件。相反,将事件添加到父元素以获得所需的效果:
That's because when you hide the element, mouseout event fires also as the cursor is no more on the element. Instead, add the event to the parent element to get the desired effect: