2013-05-28 69 views
8

我正在使用.toggle()jquery展開/摺疊。如何更改.toggle()的展開方向?

您是否知道如何從底部到頂部改變展開/摺疊方向而不是從左上角到右下角?我不是專家的jQuery,我發現了演示,並使用這些代碼...

這是我的工作文件:http://www.streetlightministries.ca/2013 - 然後點擊右上角的「時報&位置」。你會看到它從左上角擴展到右下角。我寧願讓它從下到上擴大。

如果您能夠幫助我,我將非常感激!

感謝

回答

9

對於初學者,我會使用.slideToggle()而不是切換。它只是一個簡單的崩潰和擴大。先嚐試一下,看看你是否更喜歡那個結果。

+0

這正是我所期待的:) – user1717475

3

您正在尋找slideToggle

如果幸運的話,您只需將toggle()更改爲slideToggle()即可。

+0

我試過,但它沒有工作,我認爲這是因爲切換()和的slideToggle()使用不同的jQuery的。謝謝你的幫助! – user1717475

+3

嗯,我不明白這是不是工作,但其他答案工作,因爲它是完全一樣的,但無論如何,它的工作,這就是問題! –

2

試試這個

$('blah').toggle('drop', {direction: 'right'}, 150) 
0

試試這個,使用回調財產

<script type="text/javascript"> 
      $(document).ready(function() {       
       $(".scCollapAnchor").click(function() { 
        $('.iiColapsable').toggle("slide", 
         { 
          direction: 'up', 
          complete: function() { 
           if ($('#spanCollapsable').hasClass('glyphicon-chevron-down')) { 
            $('#spanCollapsable').removeClass('glyphicon-chevron-down'); 
            $('#spanCollapsable').addClass('glyphicon-chevron-up'); 
           } 
           else { 
            $('#spanCollapsable').removeClass('glyphicon-chevron-up'); 
            $('#spanCollapsable').addClass('glyphicon-chevron-down'); 
           } 
          } 
         }, 400); 
       }); 
      }); 
     </script>