2012-05-08 25 views
0

所以我有這個網站:http://webzilla-il.com/contactus.php,現在我知道它不是英文,但文本並不重要什麼是jQuery的重要,請嘗試點擊紫色區域上的每個圖像,你可以看到一個div幻燈片的一些文章了,現在就來試試點擊快速上一個又一個,在申報單顯示向上滑動完成之前的圖像,並使它看起來很糟糕......如何等待直至效果結束? (我看着重複)

到目前爲止我的代碼是:

//Contact us 
$(document).ready(function(){ 
    $(".box").click(function(){ 
     var name = $(this).attr("name"); 
     $(".sform").slideUp().promise().done(function() {     
      switch(name){ 
       case "skype": 
        $('.sform[name="'+name+'"]').next().promise().done(function() {$(this).css("margin-left","4px")}); 
        $('.sform[name="'+name+'"]').slideDown(); 
        break; 
       case "form": 
        $('.sform[name="skype"]').next().promise().done(function() {$(this).css("margin-left","60px")}); 
        $('.sform[name="'+name+'"]').slideDown(); 
        break; 
       case "email": 
        $('.sform[name="skype"]').next().promise().done(function() {$(this).css("margin-left","60px")}); 
        $('.sform[name="'+name+'"]').slideDown(); 
        break; 
      } 
     });    
    }); 
}); 

我的HTML:

<div id="contact_forms"> 
     <div class="cform sform" style="margin-left: 60px; display: none;" name="skype"> <!--Skype--> 
      <div class="skypes"> 
      <h5><a class="cf" href="skype:londneramit">londneramit</a></h5> 
       עמית לונדנר 
      </div> 
      <br /> 
      <div class="skypes" name="skype"> 
       <h5><a class="cf" href="skype:dan_barzilay">dan_barzilay</a></h5> 
       דן ברזילי 
      </div> 
     </div> 
     <div class="cform" style="margin-left: 60px; visibility: hidden;"></div> 

     <div class="cform sform" name="form"> <!--Form--> 
      <div id="webzilla_contact_us" style="border: none;"> 
       <form method="POST" onsubmit="return contactUs(this)"> 
        <input type="text" name="name" /> 
        <input type="email" name="email" /> 
        <input type="text" name="title" /> 
        <br style="clear: both;" /> 
        <textarea name="content"></textarea> 
        <input type="submit" name="contactsub" value="שלח!"/> 
       </form> 
      </div> 
     </div> 
     <div class="cform" style="visibility: hidden;"></div> 

     <div class="cform sform" style="display: none;" name="email"> <!--Email--> 
      <h6><a class="cf" href="mailto:[email protected]">[email protected]</a></h6> 
      <div id="breaker"><img src="img/Contact/shadow_breaker.png" alt="breaker" /></div> 
      <div class="emails"> 
       <h5><a class="cf" href="mailto:[email protected]">[email protected]</a></h5> 
       עמית לונדנר 
      </div> 
      <br /> 
      <div class="emails"> 
       <h5><a class="cf" href="mailto:[email protected]">[email protected]</a></h5> 
       דן ברזילי     
      </div> 
     </div> 
    </div> 

正如你可以看到我已經tryed承諾()。完成()...

感謝您的幫助。

+0

你需要這樣的東西清除動畫隊列,然後完成所有當前動畫執行click事件 – Huangism

回答

0

東西更簡單,

這是什麼原因你企圖達到?

Demo

1

編輯:

$('.sform').not(":visible").slideUp(function() { 
      // will be called when the element finishes fading out 
      // if selector matches multiple elements it will be called once for each 
      switch(name){ 
        case "skype": 
         $('.sform[name="'+name+'"]').next().promise().done(function() {$(this).css("margin-left","4px")}); 
         $('.sform[name="'+name+'"]').slideDown(); 
         break; 
        case "form": 
         $('.sform[name="skype"]').next().promise().done(function() {$(this).css("margin-left","60px")}); 
         $('.sform[name="'+name+'"]').slideDown(); 
         break; 
        case "email": 
         $('.sform[name="skype"]').next().promise().done(function() {$(this).css("margin-left","60px")}); 
         $('.sform[name="'+name+'"]').slideDown(); 
         break; 
       } 

     }); 

Documentation

+0

不會這導致事情上下滑動了許多次你點擊?即使它會排隊他們,但他們都會顯示不是他們? – Huangism

+0

我試過,但它沒有工作:/ –

0

試試這個

$(".sform").stop(true, true).slideUp().promise().done(..) 

這可能給一些運氣:

$(".sform:animated").slideUp(100).promise().done(..) 

$(".sform:animated").slideUp(100, function() { 
    switch(name) {...} 
}) 

您可以檢查出duration

+0

你可能想使用.stop(true,true),所以它會返回到原來的位置。 – Brian

+0

剛剛上傳它與您的代碼,所以你可以看到自己 –

+0

玩停止(),它應該工作,嘗試設置真假爲不同的組合。不要指望每個人都給你喂匙子 – Huangism

0

我的工作的防火牆沒有讓我看看你的網站出於某種原因,而是看你的代碼,你也許能夠使用的回調嘗試而不是:

$(".sform").slideUp(function() {     
    switch(name){ 
     case "skype": 
      $('.sform[name="'+name+'"]').next().promise().done(function() {$(this).css("margin-left","4px")}); 
      $('.sform[name="'+name+'"]').slideDown(); 
      break; 
     case "form": 
      $('.sform[name="skype"]').next().promise().done(function() {$(this).css("margin-left","60px")}); 
      $('.sform[name="'+name+'"]').slideDown(); 
      break; 
     case "email": 
      $('.sform[name="skype"]').next().promise().done(function() {$(this).css("margin-left","60px")}); 
      $('.sform[name="'+name+'"]').slideDown(); 
      break; 
    } 
});  
+0

試過它沒有工作...:/ –

+0

它有相同的行爲或不同的東西? – Brian

+0

Iv'e現在上傳了您的代碼,以便您可以親眼看到 –

0

這是因爲你每次點擊任何一個對象時都會對所有的方框調用SlideUp。

$(".sform").not(":visible").slideUp().promise().done(function() {  

...  
+0

Sry:/不工作...... –