2011-07-27 41 views
0

我有一個框,我想點擊鏈接時進行動畫處理。鏈接在盒子內 - 因此我無法隱藏盒子並使用簡單的slideToggle函數。 我希望框可以滑動到位置bottom:0px;再次單擊時,它應滑動到底部:-71px;jQuery動畫框

這是我的盒子」 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 --> 

這是jQuery的迄今爲止

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

但是,這並不工作,所以有人可以幫我嗎? :)

+0

演示請解釋_exectly_什麼不起作用? – andyb

+0

['.click()'](http://api.jquery.com/click/)方法不接受兩個處理程序。你想在兩者之間切換? – jensgram

+0

OT:你應該帶一個[jsfiddle.net](http://jsfiddle.net)例子 –

回答

1

使用toggle-event方法。

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

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

0

嘗試

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

只是好奇,但你爲什麼必須先打電話給STOP?你究竟在幹什麼? –

+0

@Prisoner,從前次點擊的動畫(*如果還沒有結束*) –

+0

啊!陷阱....非常感謝你!還有一件事,調用STOP是否將對象返回到原始(默認)狀態(或位置)?或者它只是停止以前的動畫(無論現在在哪裏)? –