2014-07-17 53 views
1

我用3秒的拖放效果,但它不能正常工作。它喜歡顯示/隱藏,沒有下降3秒。 有什麼建議嗎?jquery切換拖放效果無法正常工作

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#imagem").click(function(ev) { 
      ev.stopPropagation(); 
      ev.preventDefault(); 
      if ($("div.principal").is(":visible")) { 
       $("div.principal").toggle('drop', 3000); 
       $("div.tudo").width("675px"); 
      } else { 
       $("div.principal").toggle('drop', 3000); 
       $("div.tudo").width("1121px"); 
      } 
     }); 
    }); 
</script> 
+0

使用[.animate()](http://api.jquery.com/animate/)取而代之的是更多的控制,並且仍然易於使用 – Banana

+0

什麼是「drop」? – isherwood

回答

0

附近我可以告訴,這不是股票jQuery toggle()函數的工作原理。然而,jQuery UI的確實有一個 '降' 選項,你的代碼完美的作品時,庫中被引用:

HTML

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="myApp"> 
    <head> 
     <title>TestBed</title> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
     <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/themes/smoothness/jquery-ui.css" /> 
     <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script> 
     <script src="app/script.js"></script> 
     <link href="Content/site.css" rel="stylesheet" /> 
    </head> 
    <body> 
     <p id="imagem">ImageThing</p> 
     <div class="principal">Principal</div> 
     <div class="tudo">Tudo</div> 
    </body> 
</html> 

的JavaScript

'use strict'; 

$(function() { 
    $("#imagem").click(function(ev) { 
     ev.stopPropagation(); 
     ev.preventDefault(); 
     if ($("div.principal").is(":visible")) { 
      $("div.principal").toggle('drop', 3000); 
      $("div.tudo").width("675px"); 
     } else { 
      $("div.principal").toggle('drop', 3000); 
      $("div.tudo").width("1121px"); 
     } 
    }); 
}); 
0

我不知道如果切換需要2個參數。如果你試圖延遲3秒的切換,那麼這可能會起作用。它爲我工作。

$(「div.principal」)。delay(3000).toggle('drop');