2011-09-16 3 views
1

전자 상거래 사이트의 백 오피스 용 테이블을 만들었습니다. 테이블 내용 (tbody)은 고정 된 높이를 가지고 있으며 다음 그림과 같이 오른쪽에있는 스크롤 바를 통해 스크롤 할 수 있습니다. http://img690.imageshack.us/img690/6483/screenshot20110917at819.png창 크기를 조정할 때 테이블 스크롤 막대가 사라짐

문제는 브라우저 창 크기를 조정하면이 테이블 스크롤바에 문제가 있다는 것입니다. http://img26.imageshack.us/img26/4919/screenshot20110917at820.png

정상적인 동작으로 알고 있지만 내 고객은 창 크기를 조정할 때 테이블 스크롤 막대를 유지해야한다고 주장합니다. 이 동작을 구현할 수있는 방법이 있습니까? 여기

가 참조 할 수 있도록 CSS 있습니다 : (테이블 본체의 클래스가 scrollContent입니다)

/* define height and width of scrollable area. Add 16px to width for scrollbar */ 
div.tableContainer { 
    clear: both; 
    overflow: auto; 
    width: 100%; 
} 

/* set table header to a fixed position. WinIE 6.x only           */ 
/* In WinIE 6.x, any element with a position property set to relative and is a child of   */ 
/* an element that has an overflow property set, the relative value translates into fixed. */ 
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to  auto */ 
thead.fixedHeader tr { 
    position: relative 
} 

/* set THEAD element to have block level attributes. All other non-IE browsers    */ 
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */ 
html>body thead.fixedHeader tr { 
    display: block; 
    width: 100% 
} 

/* define the table content to be scrollable             */ 
/* set TBODY element to have block level attributes. All other non-IE browsers   */ 
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */ 
/* induced side effect is that child TDs no longer accept width: auto      */ 
html>body tbody.scrollContent { 
    display: block; 
    overflow-y: auto; 
    overflow-x: hidden; 
    width: 100%; 
} 
+0

CSS만으로는 그렇게 생각하지 않습니다. 당신이 할 수있는 최선의 방법은'body'에'min-width'를 설정하면, 윈도우의 수평 스크롤 바를 사용하여 오른쪽으로 스크롤하면 테이블의 수직 스크롤바가 보입니다. JavaScript/jQuery가 옵션입니까? – thirtydot

+0

페이지의 일부 html/데모/more를 볼 수 있습니까? –

+0

JavaScript/JQuery는 테이블 내용을 정렬하기 위해 기존 스크립트와 충돌하지 않으면 확실히 옵션입니다. 필자는 코드 정리에 끔찍한 방법을 가진 두 명의 다른 개발자가 프로젝트를 진행해야한다는 것을 인정해야합니다. 하지만 간단한 해결책이 자바 스크립트에 존재한다면, 나는 확실히 그것을 사용할 것이다. –

답변

1

사실을 변경할 경우 오버 플로우 엑스 : 스크롤하거나 자동으로 문제를 해결해야한다. 그것이 숨겨져 있기 때문에 그들은 아마 그들의 불만 인 스크롤 막대에 접근 할 수 없다.

다른 옵션은 화면 해상도를 확인한 후 다른 테이블로 바꾸거나 작은 이미지로 바꾸는 javascript 또는 jquery를 실행하는 것입니다. 이렇게하면 표가 크기를 줄여 최대화되지 않은 창에 표시 될 수 있습니다.

/---- 편집 ----/

확인 창 크기 조정 (당신은 또한 당신이 요소에 그것을 할 수 있지만 윈도우가 당신에게 줄 것이다 창에서이 작업을 수행 할 필요가 없습니다 더 . 그들의 창 크기를 조절 여부에 대한 정확한 읽기

var timerID = 0, 
var winWidth = $(window).width(), 
var winHeight = $(window).height(); 

$(document).ready(function() 
{ 
    $(window).resize(function() 
    { 
     var winNewWidth = $(window).width(), 
      winNewHeight = $(window).height(); 
     if(winWidth != winNewWidth || winHeight != winNewHeight) 
     { 
      window.clearTimeout(timerID); 
      timerID = window.setTimeout(function() 
      { 
       // do something here 
      },100) 
     } 
     winWidth = winNewWidth; 
     winHeight = winNewHeight 
    }); 
}); 
+0

그들은 실제로 가로 스크롤 막대가 숨겨 지길 원합니다. 문제는 크기를 조정할 때 창의 오른쪽 가장자리를 따르지 않는 세로 스크롤 막대에서 발생합니다. –

+0

해상도 확인과 관련하여 창 크기를 조정할 때에도 스크롤바가 항상 표시되어야합니다. 나는 jQuery 윈도우를 사용할 수 있다고 생각한다.그 때 onresize. –

+0

은 클라이언트가 jquery window.resize를 원한다는 기준에 따라 가장 좋은 개념 일 것입니다. 내 편집보기 – CBRRacer

0

변경 CSS에서 oversflow 행동이 항상 같이 표시합니다 :

나중에이 페이지를 방문하는 사람들에게 참고로
+0

아마도 제 질문을 올바르게 물어 보지 않았을 수 있습니다. 주석에서 말했듯이 스크롤바는 실제로 "사라지다"는 것이 아니라 크기를 조정할 때 브라우저 창의 오른쪽 가장자리를 따르지 않습니다. –

0

html>body tbody.scrollContent { 
    display: block; 
    overflow-y: scroll; //this will make sure to always display the scrollbar, whether it's active (available for scrolling) or not. 
    overflow-x: hidden; 
    width: 100%; 
} 
, 여기에 최종 코드가 있습니다 :

var winWidth = $(window).width(); 
var winHeight = $(window).height(); 
var winWidthDiff = 0; 
var winHeightDiff = 0; 
$i('scrollContent').style.maxWidth= ((winWidth-16)+"px"); 
$(window).resize(function(){ 
     var winNewWidth = $(window).width(); 
     var winNewHeight = $(window).height(); 
     winWidthDiff = winNewWidth - winWidth; 
     winHeightDiff = winNewHeight - winHeight; 
     winWidth = winNewWidth; 
     winHeight = winNewHeight; 
     scrollWidth = scrollWidth + winWidthDiff; 
     scrollHeight = scrollHeight + winHeightDiff; 
     $i('scrollContent').style.maxWidth= ((winWidth-16)+"px"); 
}); 
관련 문제