스크롤 할 때 요소가 현재 뷰포트에 있는지 확인하는 스 니펫이 있습니다.여러 if 문없이 여러 요소보기
이제 여러 요소를 믹스에 추가하고 싶지만 각 if 문을 검사하지 않도록하고 싶습니다. 다음 코드는 작동하지 않지만 어떻게 처리 할 것인지 예를 들어 있습니다. 이런 식으로하는 방법이 있습니까?
var listOfPanels = $('#item2, #item2, #item3, #item4, #item5');
$(window).scroll(function(event) {
// if the element we're actually looking for exists
if (listOfPanels.length){
// check if the element is in the current view using the attached function
// and the event hasn't already fired
if (isElementInViewport(listOfPanels)) {
// do something
}
}
});
http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport/7557433#7557433 : 인이 답변을 확인 정말 도움이됩니다. – Jai
@Jai 내가 alreday, 뷰포트 조각이의 내가 할 수없는 – rogy