首页 文章

jQuery淡入淡出效果只能工作一次

提问于
浏览
1

所以我有一个div自动设置为在页面加载时不显示 . 单击特定链接时,应显示fadeIn'low',反之亦然fadeOut .

fadeIn在http请求后第一次单击时工作,但fadeOut不会(但会关闭) . 在第一次之后,整个淡化效果根本不起作用 . 然后它表现得好像是hide()和show()

代码:

$('#req_login, #srch_login').click(function() {
    $('#popbox, #popbox_bg').show(0); // opacity background
    $('#popbox #container').fadeIn('slow'); // actual div with content
    $("#email_alt_lgn").focus(); // first field in form

    // close popbox with escape key
    $(document).keyup(function(e) {
        if (e.keyCode == 27) { 
            $('#popbox_close').click(); // trigger close link
        }
    });
});     
$('#popbox_close').click(function() {
    $('#popbox #container').fadeOut('slow'); // actual div with content
    $('#popbox, #popbox_bg').hide(0); // opacity background
});

HTML:

// this is the part that should fadeIn() and fadeOut()
<div id="popbox" style="display: none;">
    <div id="container">
        <form method="POST" action="" name="login_form">
            <span style="float: right;"><a id="popbox_close" class="button makeCircle"     title="Sluiten of [Esc]">X</a></span>
            (... form content omitted)
        </form>
    </div>
</div>
<div id="popbox_bg" style="display: none;"></div>

// this is what should trigger the fadeIn() event
<a id="req_login">Inloggen</a><span class="pin_split_white"></span>

1 回答

  • 1

    我认为你的问题是这一行:"close"在"close"点击处理程序中 .

    问题是 hide() 方法将在调用 fadeOut() 之后立即调用(在 fadeOut 完成之前) . 删除它,看看它是否有效 .

    对不起,如果这不能解决它,但没有小提琴,这是我能为你做的最好的 .

    祝好运 :)

相关问题