뷰포트에있는 .column
클래스의 모든 인스턴스에 클래스를 추가하려고합니다. .addClass()가 JS Fiddle 외부에서 작동하지 않습니다.
.column
에 클래스
.swoosh
을 추가 할 수 있지만 내 마크 업 똑같은 JS를 사용하는 경우는 뷰포트에서
.column
에
.swoosh
클래스를 추가하지 않습니다.
- jquery가로드되고 있는지 확인했습니다. 그것은, this page에서 뷰포트에서
.column
클래스.swoosh
을 받고되지 않습니다 JS 바이올린
에 그러나 어떤 이유로 작동하기 때문에
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document. documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document. documentElement.clientWidth)
);
}
$.fn.checkViewportAndSetClass = function() {
$(this).each(function(){
if (isElementInViewport(this)) {
$(this).addClass("swoosh");
}
});
};
$('.column').checkViewportAndSetClass();
$(window).on("scroll", function() {
$('.column').checkViewportAndSetClass();
});
$ (document).이 경우에는 이벤트가 윈도우에 바인딩되어 있기 때문에 .ready()가 필요하지 않습니다. – mcbex
뷰포트의 모든 .column 인스턴스는 여전히'.swoosh' 클래스를 얻지 못합니다. 내 라이브 페이지 링크를 확인하고 jQuery를 추가하면로드됩니다. –
방금 다시 보았고 요소에 swoosh 클래스가 있습니다. – mcbex