Codecademy "대화 형 웹 사이트 만들기"과정을 따르고 있습니다. 나는 오류가 없지만 이해하지 못하는 것에 대해 질문이있었습니다. 슬라이드에 사용 된 if 문이 있습니다.
if (nextSlide.length === 0) {
nextSlide = $('.slide').first();
nextDot = $('.dot').first();
};
이 if 문은 마지막 슬라이드 이후 첫 번째 슬라이드로 이동합니다. 왜 그렇 nextSlide.length === 0
습니까?
jQuery :
var main = function() {
$('.dropdown-toggle').click(function() {
$('.dropdown-menu').toggle();
});
$('.arrow-next').click(function() {
var currentSlide = $('.active-slide');
var nextSlide = currentSlide.next();
var currentDot = $('.active-dot');
var nextDot = currentDot.next();
if (nextSlide.length === 0) {
nextSlide = $('.slide').first();
nextDot = $('.dot').first();
};
currentSlide.fadeOut(600).removeClass('active-slide');
nextSlide.fadeIn(600).addClass('active-slide');
currentDot.removeClass('active-dot');
nextDot.addClass('active-dot');
});
};
$(document).ready(main);
이 if
문은 현재 슬라이드 뒤에 슬라이드가 있는지 또는 첫 번째 슬라이드로 돌아 가야하는지 여부를 확인하는 것입니다.
nextSlide.length
다음 슬라이드가 있는지 여부를 나타내는 숫자를 반환하고 그렇지 않으면 0을 반환합니다.
.length
API 문서 : 여기
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다