两个jQuery效果之间的冲突

时间:2014-06-01 10:15:56

标签: javascript jquery conflict fadeout

我有这个"弹出"当我的网站上的某个用户登录/注销或提交包含错误的表单时,会显示该信息。

使用jQuery I" fadeOut"它有5秒的延迟。弹出窗口的右上角还有一个小十字架,它与click事件相关联,触发了fadeOut效果但没有任何延迟。

我的问题是,我似乎无法让它在一起工作,但是这些工作正常。

请帮帮我,谢谢!

以下是代码:

$().ready(function() {
    $( ".msg_alerte" ).delay(5000).fadeOut();

    $('#msg_alerte_cross').click(function() {
       $( ".msg_alerte" ).fadeOut();
    });
});

这是我的#34;弹出式广告"这实际上是一个简单的div

<div class="msg_alerte">
    <i>Successful login</i>
    <img id="msg_alerte_cross" src="../images/close-cross.png" />
</div>

1 个答案:

答案 0 :(得分:0)

当然,您可以在每个fadeOut之前添加stop();

$( ".msg_alerte" ).delay(5000).stop().fadeOut();
$( ".msg_alerte" ).stop().fadeOut();

但我宁愿使用jquery:animate伪选择器(http://api.jquery.com/animated-selector/); 当自动淡出开始时,无需通过单击触发隐藏它。

$( ".msg_alerte" ).delay(5000).fadeOut();

$('#msg_alerte_cross').click(function() {
   $( ".msg_alerte").not(':animated').fadeOut();
});