2013-05-19 246 views
0

我在寻找的是让我的容器调整onclick。JQUERY收听点击事件

容器内部是2个面板,滑动下来的高度不同。我需要容器来监听切换功能,并根据需要调整大小。

继承人的代码,那么远,

$(document).ready(function() { 

    var content = $("#content_container"); 
    var childHeight = $('.panel-container').height(); 

    if (content < childHeight) { 
     $(content).css("height", 657 + "px"); 
    } 

    else { 
     $(content).css("height", "auto"); 
    } 

}); 

PS。我是jQuery新手!

+0

设置你的容器自动的高度将不起作用??? –

回答

0

你可以用下面这样的东西,我不确定这是你想要的,但你可以用它来搞定它,并得到它想要的样子;

$(document).ready(function() { 

    $("#content_container").toggle(
     function() { 
      $(this).animate({height: 657}, 200); 
     }, 
     function() { 
      $(this).animate({height: 200}, 200); 
     } 
    ); 

}); 

工作示例http://jsfiddle.net/CarlG/x6yLj/2/