所以我有一个图像旋转脚本,我正在为客户端。我对它的唯一问题是,它不会像我希望的那样从上到下按顺序进行。图像旋转脚本不按顺序
的问题
,我有一个问题是,它会采取图像,有时表现出同样的图像回互相备份这是一件好事,我真的不想的原因。如果你想看看到目前为止我在做什么,这里是JsFiddle。
东西可以工作
是否有可能对我来说,id
添加并在每个图像,然后控制这样的顺序?
HTML
<section class="demo">
<button class="next">Next</button>
<button class="prev">Previous</button>
<div class="container">
<div style="display: inline-block;">
<img src="http://placehold.it/100x100"/>
</div>
<div>
<img src="http://placehold.it/200x200"/>
</div>
<div>
<img src="http://placehold.it/300x300"/>
</div>
<div>
<img src="http://placehold.it/400x400"/>
</div>
<div>
<img src="http://placehold.it/500x500"/>
</div>
<div>
<img src="http://placehold.it/600x600"/>
</div>
<div>
<img src="http://placehold.it/700x700"/>
</div>
</div>
</section>
CSS
.container {
max-width: 400px;
background-color: black;
margin: 0 auto;
text-align: center;
position: relative;
}
.container div {
background-color: white;
width: 100%;
display: inline-block;
display: none;
}
.container img {
width: 100%;
height: auto;
}
button {
position: absolute;
}
.next {
right: 5px;
}
.prev {
left: 5px;
}
jQuery的
var currentIndex = 0,
items = $('.container div'),
itemAmt = items.length;
function cycleItems() {
var item = $('.container div').eq(currentIndex);
items.hide();
item.css('display','inline-block');
}
$('.next').click(function() {
currentIndex += 1;
if (currentIndex > itemAmt - 1) {
currentIndex = 0;
}
cycleItems();
});
$('.prev').click(function() {
currentIndex -= 1;
if (currentIndex < 0) {
currentIndex = itemAmt - 1;
}
cycleItems();
});
个
非常感谢, 亚历
顺序是“人 - >任何 - >自然 - >建筑 - >动物 - >人(再次) - >高科技”,它可以围绕在一起..我可以问一下问题是什么? –
我觉得有一个问题与PlaceImg加载相同的图像,而不是与您的代码。这是一个使用placehold.it的小提琴,按顺序编号:https://jsfiddle.net/qa5yk6q7/1/ –
它们不是静态图像。所以人和任何人都可以是相同的图像。你的代码工作正常 – Fabricator