1
주어진 하위 요소를 상위 내에서보기로 스크롤하는 함수를 만들었습니다. 다음과 같이 간다 : jQuery advice : 요소를 스크롤하기 위해이 기능을 개선하려면 어떻게해야합니까?
function keepScrolledOver(elem)
{
frame = elem.parent();
var scrollPos = frame.scrollTop();
var offset = elem.attr("offsetTop");
// If the element is scrolled too high...
if(offset < scrollPos)
{
frame.scrollTop(offset);
// frame.attr("scrollTop", offset);
}
// If the element is scrolled too low...
else
{
var frameHeight = frame.height();
var offsetBottom = offset + elem.height();
var scrollBottom = scrollPos + frameHeight;
if(offsetBottom > scrollBottom)
{
// frame.attr("scrollTop", offsetBottom);
if(frameHeight < offsetBottom)
frame.scrollTop(offsetBottom - frameHeight);
// frame.attr("scrollTop", offsetBottom - frameHeight);
}
}
}
지금까지, 내 파이어 폭스 웹 앱 (파이어 폭스 내가 지금까지, 내 말에 그것을 테스트 한 모든입니다)이 잘 작동합니다. 오직 문제는 너무 낮게 스크롤 된 요소의 경우 항상 끝까지 대상 요소보다 작은 비트를 스크롤하는 경향이 있다는 것입니다. 엘리먼트 패딩과 무언가 관련이 있는지 확실하지 않습니다. 그렇지 않으면 수학 문제가 해결됩니다.
누구나 개선 방법에 대한 훌륭한 아이디어가 있습니까?