我无法让 live() 表现得像悬停()
我在 jQuery 1.4 中的实时绑定方面遇到了一个非常大的问题。我想将悬停事件绑定到 div.message 元素并淡入控件。它们默认是隐藏的。使用 .hover()
时这很容易,但不会绑定通过 ajax 添加的新项目。我尝试过 .live()
但没有成功。每次光标移动到消息的各种内容上时,它都会触发 mouseover
和 mouseout
事件。正如您可以想象的那样,这会使控件闪烁。我希望当鼠标悬停在消息上时控件淡入。但我需要在加载新消息时将效果绑定到它们。我反对在加载消息时绑定悬停事件。我更喜欢像 live 这样的解决方案,但工作原理与悬停完全一样。
<div id="messages">
<div class="message">
<div class="controls">
<a href="dosomthing">
do somthing
</a>
<a href="dosomthing">
do somthing
</a>
</div>
<p>blah blah blah</p>
</div>
<div class="message">
<div class="controls">
</div>
<p>blah blah blah</p>
</div>
<div class="message">
<div class="controls">
<a href="dosomthing">
do somthing
</a>
<a href="dosomthing">
do somthing
</a>
</div>
<p>blah blah blah</p>
</div>
</div>
I'm having a really big problem with live binding in jQuery 1.4. I want to bind a hover event to the div.message elements and fade in the controls. They are hidden by default. This is easy when using .hover()
, but doesn't bind new items that are added via ajax. I've tried .live()
with no success. It fires the mouseover
and mouseout
events every time the cursor moves over the various contents of the messages. As you can imagine this makes the controls flicker. I want the the controls to fade in when the mouse is over the message. But I need to bind the effect to new messages as they are loaded. I am apposed to binding hover events as messages are loaded. I would prefer a solution like live, but works exactly like hover.
<div id="messages">
<div class="message">
<div class="controls">
<a href="dosomthing">
do somthing
</a>
<a href="dosomthing">
do somthing
</a>
</div>
<p>blah blah blah</p>
</div>
<div class="message">
<div class="controls">
</div>
<p>blah blah blah</p>
</div>
<div class="message">
<div class="controls">
<a href="dosomthing">
do somthing
</a>
<a href="dosomthing">
do somthing
</a>
</div>
<p>blah blah blah</p>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要解决此问题,您可以使用版本 中添加的
delegate
1.4.2 像这样:To workaround that, you can use
delegate
added in version 1.4.2 instead like this: