我有,我有3個孩子的div每個包含的圖像 這裏是HTML代碼圖像不滑動
<div class="container" >
<div style="display: inline-block; ">
<img src="../Images/t-shirt1.jpg"/>
</div>
<div >
<img src="../Images/ata1.jpg"/>
</div>
<div>
<img src="../Images/ata3.jpg"/>
</div>
</div>
的問題是,我的CURRENTINDEX不增加 父DIV和我認爲」爲什麼我的圖片在這裏沒有滑動 是我的jQuery代碼
var currentIndex = 0;
items = $('.container div');
console.log("Recieved images"+items);
itemAmt = items.length;
console.log("Calculate"+itemAmt);
function cycleItems() {
var item = $('.container div').eq(currentIndex);
console.log("next item");
items.hide();
console.log("next");
item.css('display','inline-block');
}
var autoSlide = setInterval(function() {
currentIndex += 1;
console.log("Interval start"+currentIndex);
if (currentIndex > itemAmt - 1) {
currentIndex = 0;
}
cycleItems();
}, 3000);
$('.next').click(function() {
cleaInterval(autoSlide);
currentIndex += 1;
console.log("Interval start");
if (currentIndex > itemAmt - 1) {
currentIndex = 0;
console.log("Interval start loop");
}
cycleItems();
});
$('.prev').click(function() {
clearInterval(autoSlide);
currentIndex -= 1;
if (currentIndex < 0) {
currentIndex = itemAmt - 1;
}
cycleItems();
});
創建一個工作模型。 –
你的代碼對我來說工作正常https://jsfiddle.net/mohamedyousef1980/xphjhk85/ –