2011-12-22 1 views
0

div의 너비에 비례하여 div의 높이를 조절하는 함수를 작성하려고합니다. 나는 window.resize에서 이벤트를 트리거하려고 시도했지만 지금까지는 운이 없다. div의 너비는 현재 원하는대로 크기가 조정되지만 포함 된 div 요소의 경계 외부에서 높이가 크기가 서로 겹치기 시작하고 제대로 배치되지 않습니다. 어떤 도움이라도 대단히 감사 할 것입니다. 미리 감사드립니다!크기 변경 jQuery .cycle() div

jQuery: 
    $(window).resize(function(){ 
     $('.bgCycle').each(function(){ 
      newHeight = $(this).parent('div').height(); 
      $(this).height(newHeight); 
      $(this).children('div').height(newHeight); 
     }) 
    }) 

    CSS: 
.bgCycle{ 
     border:1px solid red; 
     position:relative; 
     width:100% !important; 
    } 

    .imgContainerDiv{ 
     position:relative; 
     width:100% !important; 
    } 

HTML: 
<div class="bgCycle bgCycle1" style="z-index:1;"> 
    <div class="imgContainerDiv"> 
      <img src="http://localhost:8888/aleo/wp-content/uploads/2011/12/img1.jpg" style="width:100%;"/> 
    </div> 
    <div class="imgContainerDiv"> 
      <img src="http://localhost:8888/aleo/wp-content/uploads/2011/12/img2.jpg" style="width:100%;"/> 
    </div> 
</div> 
<div class="bgCycle bgCycle2" style="z-index:1;"> 
     <div class="imgContainerDiv"> 
      <img src="http://localhost:8888/aleo/wp-content/uploads/2011/12/img3.jpg" style="width:100%;"/> 
     </div> 
     <div class="imgContainerDiv"> 
      <img src="http://localhost:8888/aleo/wp-content/uploads/2011/12/img4.jpg" style="width:100%;"/> 
     </div> 
</div>    

답변

0
당신의 HTML을 보지 않고 하드

,하지만 난 $(this).parent('div').height(); 가능성이 창 높이 참조해야 같은데요 - $(window).height();를?

newHeight = $(window).height(); 

원하는대로 할 수 있습니까?

+0

HTML 출력을 추가했습니다. 나는 $ (window) .height(); 이 경우에 적용됩니다. 문제는 .imgContainerDiv가 커지지만 .bgCycle 클래스의 div를 포함하는 각각은 너비의 크기 만 조정한다는 것입니다. 내 논리는 .bgCycle의 높이가 .imgContainerDiv의 높이보다 큰 경우 둘 다 동일한 높이로 지정되고 크기가 적절하게 조정되는 것입니다. 또한 div 아래에 표시된 모든 콘텐츠가 페이지 아래로 배치되지 않습니다. – negrelja

+0

.bgCycle div에는 부모 div가없는 것 같습니다. 따라서 $ (this) .parent ('div'). height()가 작동하지 않습니까? 아마 당신이 jsFiddle (http://jsfiddle.net/)을 만들었다면 더 이해할 수 있을까요? – SpoonNZ