2013-05-19 145 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/