function doSlider(slider) {
var slider = slider;
var itemWidth = $(slider).width();
var itemCount = $(slider + "> div > a").length;
var intervalID;
_init();
intervalID = setInterval(_animate, 2000);
function _init() {
$(slider + ">div").css({
width: (itemWidth * itemCount) + "px"
});
$(slider + " div," + slider + " span").mouseover(function() {
clearInterval(intervalID);
}).mouseout(function() {
intervalID = setInterval(_animate, 2000);
});
$("#slider > .slider-prev").click({
direction: "prev"
}, _animate);
$("#slider > .slider-next").click({
direction: "next"
}, _animate);
}
function _animate(event) {
var direction = !event ? "next" : event.data.direction;
var operation = direction == "next" ? "-=" : "+=";
if (direction == "prev") {
$(slider + ">div a:last-child").clone().prependTo(slider + ">div:first-child");
return "-" + itemWidth + "px";
});
$ (slider + "> div:first-child").animate({
"left" : operation +itemWidth + "px"
},
"slow", function() {
if (direction == "prev") {
$(slider + ">div a:last-child").remove();
} else {
$(slider + ">div a:first-child").clone().appendTo(slider + ">div:first-child");
$(slider + ">div a:first-child").remove();
$(slider + ">div a:first-child").css("left", "0");
}
});
}
위 코드에서 다음과 같은 오류가 있습니다.
1. 코드 32라인에 문법 오류가 있고 코드가 누락되었습니다. 다음 아래 코드로 수정하셔야 합니다.
$(slider + ">div:first-child").css("left", function() {
return "-" + itemWidth + "px";
});
2. 마지막 라인에 } 가 빠졌습니다.
3. 코드 44 라인에 선택자 오류가 있습니다. 아래와 같이 수정하셔야 합니다.
$(slider + ">div:first-child").css("left", "0");