2013-08-23 83 views
1

我有一个div标签:股利上点击JQuery的展开

<div id="tier1" class="tier1" > 
    <a href="#" class="view">View All</a> 
    </div> 


.tier1 { 
    border-bottom: 1px solid #cccccc; 
    min-height: initial; 
    max-height: 245px; 
    padding: 0 0 8px; 
} 

我想扩大这个div超越max-height每当我在"View All"

单击我使用这个脚本:

<script> 
          $(document).ready(function() { 


           $('.view').click(function() { 

            $('#tier1').animate(function() { 
             height : 510 ; 
            }, 1000); 
           }); 
          }); 

         </script> 

但是这扩展到只有最大高度。我甚至尝试在脚本中设置maxHeight属性但是脚本根本不起作用。

+2

似乎不太可能,运行在所有的,因为'高度:510px;'是一个语法错误。 –

+0

你不能使用'animate(function()'的方式来做动画,看看我的答案 – Anton

回答

2

试试这个代码

<script> 
     $(document).ready(function() { 

      $('div.cls:first') 
      $('.view').click(function() { 
       $('#tier1.tier1').css("max-height", "1024px"); 
       $('#tier1').css("height", "510px").animate(function() { 

       }, 1000); 
      }); 
     }); 

         </script> 
+0

感谢它按照我的要求工作! – punter

0

Amigo,你正在扩大你的div到一个新的高度,但你的课程保持不变,你没有解释课程,所以它停留在定义的最大高度。因此,在这种情况下,您必须扩展类而不是div或两者。

+0

我用我的句子写得很多:( – JonathanRomer

+0

如何扩展我的CSS类?你能请帮忙? – punter

+0

查看上面的答案,只需做$('。tier1')而不是$('#tier1')。这意味着一个类#表示一个ID。 – JonathanRomer

0
function() { 
    height: 500px 
} 

是不正确的.animate();

像这样做,而不是

$('#tier1').animate({ 
     height: 500 
    }, 1000) 

DEMO

Animate documentation

0
<script> 
          $(document).ready(function() { 


           $('.view').click(function() { 

            $('.tier1').animate(function() { 
             $(this).css('max-height','510px'); 
            }, 1000); 
           }); 
          }); 

         </script> 
0

试试这个

$(document).ready(function() { 
     $('.view').click(function() { 
      var toggle_switch = $(this); 
      $("#tier1").toggle(function() { 

      }); 
     }); 

    });