2013-05-21 4 views
6

jQuery 모바일 응용 프로그램에 "변경 로그"를 추가하려고합니다. 오류가 발생한 경우 사용자는 무엇이 잘못되었는지 파악할 수있는 기능이 있어야합니다.jQuery-Textarea의 맨 위로 스크롤

$('#showLog').click(function() { 
    $("#popupDialog").popup("close"); 
    // populate the textArea with the text 
    $("#popupTextArea").text(sessionStorage.getItem("logStack")); 
    // open popUp after a specific time 
    setTimeout(function(){$('#popupLog').popup('open'); 
     }, 1000); 
}); 

모든 기능이 잘 작동 : 그 때문에 나는 텍스트 영역 더불어, 팝업을 구현 한 특정 버튼을 클릭하면이 pop-up가 데이터로 채워 및 열

 <!-- DIALOG Start--> 
     <div data-role="popup" id="popupLog" data-overlay-theme="a" data-theme="b" style="max-width:400px;" class="ui-corner-all"> 
     <div data-role="header" data-theme="b" class="ui-corner-top"> 
     <h1>Logg-Einträge:</h1> 
     </div> 
     <div data-role="none" data-theme="b" class="ui-corner-bottom ui-content"> 
     <textarea style="height: 120px; max-height: 120px" readonly="readonly" data-mini="true" cols="40" rows="8" id="popupTextArea"></textarea> 
     <a href="#" data-role="button" data-inline="true" id="btn_textArea" data-rel="back" data-theme="c">OK</a>  
     </div> 
     </div> 
     <!-- DIALOG End--> 

(아래 코드 참조) 여기까지. 문제는 다음과 같습니다. 사용자가 텍스트 영역 내에서 스크롤을 내리고 팝업을 닫은 다음 다시 열면 스크롤러의 위치는 여전히 동일합니다. 예를 들어 사용자가 아래로 스크롤 한 다음 팝업을 닫고 다시 엽니 다. popUp은 텍스트 영역의 하단에 있습니다. 하지만 popUp이 다시 열릴 때 textarea의 꼭대기에 항상 머물고 싶습니다. 이를 실현을 위해, 나는 0으로 scrollingTop를 팝업을 닫으로는 다음이 팝업창에서 "확인"- 버튼을 구현하고 설정 한 :

$('#btn_textArea').click(function() { 
// Setting position of the textArea to "0" -> But doesn't work..... 
    $('#popupTextArea').scrollTop(0); 
    ); 
}); 

나는이 시점에서 struggeling있어을의 모양 때문에 textArea는 여전히 동일합니다. 새로 고침이나 다른 것이 필요합니까? 내가

답변

1

당신은 텍스트 영역의 scrollTop 속성을 조작하는 "popupbeforeposition"이벤트를 사용할 수 있습니다 .... 모든 도움을 매우 감사하게 될 것입니다 : 여기

$(document).ready(function(){ 

    $("#exampleWindow").on("popupbeforeposition", function(evt, ui){ 

     $(this).find("textarea").scrollTop(0); 

    }); 

}); 

당신은 예를 가진 jsfiddle 있습니다 http://jsfiddle.net/elchininet/eBp7S/

관련 문제