2012-11-19 5 views
1

Illustration외부 div 높이를 초과하는 내부 div 숨기기

전체 요소가 숨겨져 있어야합니다. 바깥 쪽 div에는 스크롤바가 없어야합니다. CSS만으로 구현할 수 있습니까? 아니면 jQuery가 필요합니까? 이것이 어떻게 구현 될 수 있는가?

+2

코드를 표시 할 수 있습니까? –

+1

"오버 플로우 : 숨김"을 시도해 볼 수는 있지만 div보다 높이 (그리고 전체 div가 아닌) 부분 만 숨길 것이라고 생각합니다. – Igor

+0

전체 요소를 숨기시겠습니까? 또는 여전히 외부 div 경계 내에있는 부분을 표시합니까? – ryadavilli

답변

3

일반적인 아이디어는 다음과 같다 이것은에서 테스트되지

var sumHeight = 0; 
$("div div").filter(function() { 
    var $this = $(this), 
     pHeight = $this.parent().height();  // parent inner height 

    sumHeight += $this.outerHeight(true);  // + block outer height 

    return sumHeight > pHeight; 
}).hide(); 
+0

외부 div의 이름이 "mainLeft"이고 내부 div의 이름이 "row"인 경우 $ ("mainLeft row") 여야하나요? – mupersan82

+0

@ user1750323 아니요, 두 개의 div를 선택하지 않았습니다. 나는 div에서 div를 선택했다는 것을 보여 주었다. 당신은'$ ("# container .block")'또는 그것을 대체 할 수있다. – VisioN

+0

좋아요, 알겠습니다. 감사. – mupersan82

1

외부 div에 overflow:hidden; 속성을 추가하십시오.

$("div div").filter(function() { 
    var $this = $(this), 
     pTop = $this.parent().offset().top, // parent position 
               // (no need if parent has 
               // "position: relative") 

     pHeight = $this.parent().height(),  // parent inner height 

     eTop = $this.offset().top,    // block position 
               // (can be replaced with 
               // "$this.position().top" 
               // if parent has 
               // "position: relative") 

     eHeight = $this.outerHeight(true);  // block outer height 

    return (eTop + eHeight) > (pTop + pHeight); 
}).hide(); 

(이론적으로이 해야 작동합니다.)


또 다른 방법 :

+3

이렇게하면 가장 낮은 div가 부분적으로 숨겨집니다. –

2

모두, 그리고 매우 조정될 필요가 있지만, 당신에게 일반적인 아이디어를주기 위해 jQuery로 어떻게 할 수 있습니까?

var container = $('#container'); 
var element = $('#element'); 

if ((element.position().top + element.position.height()) > container.height()) { 
    element.hide(); 
}