물론, 당신은 입력에 포커스 이벤트 핸들러를 추가하고 위치 onfocus 및을 확인할 수 있습니다. 그것이 바닥에 너무 가깝다면, 허용 될 때까지 창 스크롤을 조금만 부딪 치십시오. 다음은
당신이 jQuery를에 그것을 할 수있는 방법은 다음과 같습니다
// Constant amount of padding an element should be from the bottom of the window
var padding = 50;
// Add focus event to all your different form elements
$("input, textarea, select").focus(function(){
// Check their position relative to the window's scroll
var elementBottom = $(this).offset().top + $(this).height();
var windowScroll = $(window).scrollTop();
var windowBottom = windowScroll + $(window).height();
if(elementBottom + padding > windowBottom){
$(window).scrollTop(windowScroll + padding);
}
});
당신은 그것을 in action here을 볼 수 있습니다.
편집 : 텍스트 영역에 입력하면
당신은 캡처하고
keydown event 처리기를 사용하여 입력하는 동안 텍스트 영역의 위치를 확인할 수 있습니다
:
이
$('textarea').keydown(function(){
// same logic as above to check textarea position relative to window
});
출처
2010-08-23 14:46:23
Pat
안녕 팻, 감사는 응답을, 나는 결국 않았다을 이렇게. 그러나 뷰포트의 하단과 겹치는 텍스트 영역에 타이핑 할 때 창은 커서로 스크롤되어 사라지지 않습니다. 이것도 바꿀 수 있습니까? – Joel
문제는 아니며 가능할 수도 있습니다. 내 수정 사항을보고 어떻게 할 수 있는지보십시오. – Pat