2011-12-29 4 views
3

사람들이 내용을 변경할 때 <textarea>의 scrollheight를 얻고 싶습니다. 문제는 콘텐츠를 추가 할 때 증가하는 scrollheight를 얻을 수 있지만 콘텐츠를 삭제할 때 할 수 있습니다. '는 t는 ... 여기에 감소 scrollheight.And 코드내용을 삭제할 때 텍스트 영역의 스크롤 높이를 얻을 수 없습니다

$("textarea[id^='_sub_ialready_']").live("keydown keyup focus blur", 
    function() 
    { 
     if(aobj.minHeight == 0) 
     aobj.minHeight = $(this).height(); 
     if($(this).attr("scrollHeight") > aobj.minHeight) 
     { 
      if($(this).attr("scrollHeight") > aobj.maxHeight) 
      { 
       nheight = aobj.maxHeight; 
       $(this).css("overflow-Y",'scroll');  
      }  
      else 
      { 
       nheight = $(this).attr("scrollHeight"); 
       $(this).css("overflow-Y",'hidden');  
      } 
      $(this).height(nheight); 
     } 
    } 
) 
+0

CSS 또는 약간을 지정할 수 있습니까? 코드가 더 많아서 우리가 뭘 더 잘 이해할 수 있을까요? 또한 scrollHeight를 가져 오는 것과 관련하여 다음 질문 중 하나를 확인해 보셨습니까? : http://stackoverflow.com/questions/5980150/jquery-js-get-the-scrollbar-height-of-an-textarea http :// /stackoverflow.com/questions/642353/dynamically-scrolling-a-textarea http://stackoverflow.com/questions/454202/creating-a-textarea-with-auto-resize – elboletaire

답변

0

무엇 약

.attr('scrollHeight') 

또는

를 얻을 수

$('#textarea').height('auto'); 

는 그 다음 scrollHeight 속성을 얻을 :

$('textarea:first').get(0).scrollHeight 

또는 무엇 당신이 원하는 것은 auto, 처음과 같이로 설정 높이

textarea.scrollHeight 
+1

문제는 : 콘텐츠를 추가 할 때입니다. 증가하는 scrollheight를 얻을 수 있지만, 내용을 삭제할 때, 나는 scrollheight을 줄일 수 없다. – ivyandrich

2

입니다 (픽셀 단위 정수를 반환)

var h = $('#textarea').prop('scrollHeight'); 
관련 문제