내 문제에 대한 답변을 찾는 데 어려움이 있습니다. 나는 다음에 가지고있는 간단한 슬라이드 쇼와 이전 버튼을 가지고 있지만, 이전 버튼을 누르면 첫 번째 이미지에서 멈 춥니 다. 첫 번째 이미지에서 마지막 이미지로 이동하지만 올바른 결과는 찾을 수 없습니다.슬라이드 쇼 만들기 img 처음부터 끝까지 이동
window.onload = function() {
var listNode = $("image_list");
var captionNode = $("caption");
var imageNode = $("image");
var links = listNode.getElementsByTagName("a");
// Process image links
var i, linkNode, image;
var imageCache = [];
for (i = 0; i < links.length; i++) {
linkNode = links[i];
// Preload image and copy title properties
image = new Image();
image.src = linkNode.getAttribute("href");
image.title = linkNode.getAttribute("title");
imageCache.push(image);
}
//next button handler
var nextButton = $("next");
var imageCounter = 0;
nextButton.onclick = function() {
imageCounter = (imageCounter + 1) % imageCache.length;
image = imageCache[imageCounter];
imageNode.src = image.src;
captionNode.firstChild.nodeValue = image.title;
}
//previous button handler
var prevButton = $("previous");
var imageCounter = 0;
prevButton.onclick = function() {
imageCounter = (imageCounter - 1) % imageCache.length;
image = imageCache[imageCounter];
imageNode.src = image.src;
captionNode.firstChild.nodeValue = image.title;
}
왜'imageCounter'를 두 번 정의합니까? – Schleis