开发者

jQuery animate box

开发者 https://www.devze.com 2023-03-23 11:27 出处:网络
I have a box i want to animate when clicked on a link. The link is inside the box - therefore i can not hide the box and the use a simple slideToggle function.

I have a box i want to animate when clicked on a link. The link is inside the box - therefore i can not hide the box and the use a simple slideToggle function. I want the box to slide to position bottom: 0px;, and when clicked again it should slide to bottom: -71px;

This is my box' HTML:

    <!-- LOGIN -->
<div id="userlogin">
    <div class="topbutton"><a href="#"><span>Log ind</span></a></div>
    <form action="" method="POST" enctype="" onsubmit="document.getElementById('_form__submit').disabled = true;" target="" id="_form__form">
        <input type="hidden" name="module" value="Brugere" id="_form__module">
        <input type="hidden" name="page" value="login" id="_form__page">
        <input type="hidden" name="do" value="" id="_form__do">
        <input type="hidden" name="id" value="0" id="_form__id">
        <input type="hidden" name="lang_id" value="da" id="_form__lang_id">
        <input type="hidden" name="_form_" id="_form_" value="submit">
        <input type="hidden" name="when_done" value="" id="when_done">

        <div class="left">
            <p><span>Brugernavn</span><input type="text" name="username" value="" id="username" class="loginfield" /></p>
            <p><span>Adgangskode</span><input type="password" name="password" value="" id="password" class="loginfield" /></p>
        </div>
        <div class="right">
            <input type="submit" id="_form__submit" class="loginbutton" value="Log ind" /><br />
            <a href="/site/da/Brugere/forgot_password"><b>»</b> Glemt adgangskode?</a>
            <iframe width="0" height="0" src="" name="_form__iframe_save" frameborder="0" framespacing="0" scrolling="no"></iframe>
        </div>
        <div class="clear"></div>
    </form>
</div>
<!-- LOGIN -->

And this is the jQuery so far

    $("#userlogin .topbutton a").click(functio开发者_StackOverflow社区n () {
    $("#userlogin").stop(true).animate({bottom: '0'}, {speed: 500});
}, function () {
    $("#userlogin").stop(true).animate({bottom: '-71px'}, {speed: 500});
});

But this doesn't work, so can someone please help me? :)


Use the toggle-event method.

$("#userlogin .topbutton a").toggle(
function() {
    $("#userlogin").stop(true).animate({
        bottom: '0'
    }, 500);
}, function() {
    $("#userlogin").stop(true).animate({
        bottom: '-71px'
    }, 500);
});

demo at http://jsfiddle.net/gaby/5ChVX/1/


Try

    $("#userlogin .topbutton a").click(function () {
    $("#userlogin").stop(true).animate({bottom: '0'}, 500);
}, function () {
    $("#userlogin").stop(true).animate({bottom: '-71px'}, 500);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消