자동 슬라이드 쇼를 만들려고하지만이 메시지가 계속 나타나고 그 이유를 모르겠습니다.정의되지 않은 'removeClass'속성을 읽을 수 없습니다.
HTML :
<section id="slideshow">
<div class="auto-slideshow">
<img src="img/pic1.jpg" alt="" class="slide show">
<img src="img/pic2.jpg" alt="" class="slide hide">
<img src="img/pic3.jpg" alt="" class="slide hide">
</div>
</section>
"표시"와 "닫기"클래스는 각각 '블록'과 '없음'으로 표시 설정.
자바 스크립트 :
autoSlideshow();
var mySlides = $('#slideshow .slide');
var slides = [];
mySlides.each(function() {
slides.push($(this));
});
function autoSlideshow() {
var index;
var next;
mySlides.each(function() {
if ($(this).hasClass('show')) {
index = $(this).index();
next = index+1;
$(this).removeClass('show').addClass('hide');
slides[next].removeClass('hide').addClass('show');
console.log('The index is: '+index);
console.log('The next one is: '+next);
};
});
setInterval(autoSlideshow, 3000);
};
어떤 조언이나 보정을 많이 감사합니다.
을 다음이 정의 될 수 있기 때문에 그것은있을 수 슬라이드 – Li357
의 양 이상이라면 그 슬라이드 [다음] 자바 스크립트 객체가 아닌 것입니다 jQuery 객체. –
아마도 함수 밖에서'setTimeout'을 사용하거나'setInterval'을 사용하기를 원할 것입니다. – putvande