http://jsfiddle.net/leonwho/L9A6Q/
웹 사이트 대시 보드에서 무한 스크롤을 개발할 준비를하고 있지만 jsfiddle mockup 에서 컨테이너 div의 하단을 결정하는 방법에 대해 고민하고 있습니다.
컨테이너 div가없는 빈 페이지에서 작동하는 원래 함수
var wireInfinScroll = function() {
console.log('in wireInfinScroll');
$('#scroll_screen').scroll(function(){
console.log('scrolling...');
console.log(' ');
//if ($('#scroll_screen').scrollTop() == $('#content').height() - $('#scroll_screen').outerHeight()) {
if ($('#scroll_screen').scrollTop() == $('#content').height() - $('#scroll_screen').height()) {
// run our call for pagination
console.log('Bottom of Page!');
alert('Bottom of Page!');
}
});
}
wireInfinScroll();
CSS
#scroll_screen {
overflow-y: auto;
background: pink;
}
내 예제에서 window
스크롤되는 div ( #scroll_screen
)로 바꾸려고 시도했지만 경고를 트리거 할 수 없습니다.
이 문제에 어떻게 접근했을까요?
업데이트
여기에 동일한 코드를 사용하여 새 jsFiddle을 만들었습니다. http://jsfiddle.net/leonwho/L9A6Q/
또한 #scroll_screen
div 내부를 클릭하지 않으면 console.logs가 표시되지 않습니다 .
Codepen을 삭제하고 jsFiddle을 사용하여 조금 더 나아갔습니다. $('#scroll_screen').scroll(function(){
노트! 내가 제거하면 height: 100%
으로부터 #content
DIV, 다음 아래로 스크롤 나는 마침내 내 얻을 백업 경고를 하지만, 이것은 여전히 올바르지 않습니다. 경고 스크롤 아래에서 발생한다
CSS
#content {
float: right;
width: 79%;
//height: 100%;
background: #f8f8f8;
}
$('#scroll_screen').height() - $('#content').height()
scroll_screen
의 높이는 항상의 높이보다 작기 때문에 음의 값을 제공 content
합니다. 즉 scroll_screen
's scrollTop
는 절대로 음의 값과 같지 않으므로
$('#scroll_screen').scrollTop() == $('#scroll_screen').height() - $('#content').height()
와
$('#scroll_screen').scrollTop() >= if ( $('#scroll_screen').scrollTop() >= -($('#content').height() - $('#scroll_screen').height()) ))
(애니메이션이 건너 뛰는 경우에만 크거나 같음)
[편집]으로 스크롤 200
되므로 if ($('#scroll_screen').scrollTop() >= 200)
작동해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다