我需要在我的页面上插入 3 个 jquery 图像旋转器(infinite-rotator.js)。每个将显示不同的图像,但所有画廊将具有相同的功能。
我已经完成了 3 个 div,每个 div 都有一个 ID。三个画廊工作,但不是同时工作。当第一个画廊图像结束时,会出现第二个画廊图像。当这些图像结束时,第三个画廊开始了。我需要 3 个画廊同时启动并相互独立运行。
我是初学者,所以如果有人可以帮助我,我会很感激。
HTML 代码:
<div id="rotating-item-wrapper">
<img src="images/inicio_mini01_01.jpg" alt="photo of building across from our office" class="rotating-item" width="308" height="303" />
<img src="images/inicio_mini01_02.jpg" alt="building entrance with neon backlit walls" class="rotating-item" width="308" height="303" />
</div>
<div id="rotating-item-wrapper2">
<img src="images/inicio_mini02_01.jpg" alt="photo of building across from our office" class="rotating-item" width="308" height="303" />
<img src="images/inicio_mini02_02.jpg" alt="building entrance with neon backlit walls" class="rotating-item" width="308" height="303" />
</div>
<div id="rotating-item-wrapper3">
<img src="images/inicio_mini03_01.jpg" alt="photo of building across from our office" class="rotating-item" width="308" height="303" />
<img src="images/inicio_mini03_02.jpg" alt="building entrance with neon backlit walls" class="rotating-item" width="308" height="303" />
</div>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=3.0.1'></script>
<script type='text/javascript' src='scripts/infinite-rotator.js'></script>
在 JAVASCRIPT 中:
$(window).load(function () { //start after HTML, images have loaded
var InfiniteRotator = {
init: function () {
//initial fade-in time (in milliseconds)
var initialFadeIn = 1000;
//interval between items (in milliseconds)
var itemInterval = 5000;
//cross-fade time (in milliseconds)
var fadeTime = 2500;
//count number of items
var numberOfItems = $('.rotating-item').length;
//set current item
var currentItem = 0;
//show first item
$('.rotating-item').eq(currentItem).fadeIn(initialFadeIn);
//loop through the items
var infiniteLoop = setInterval(function () {
$('.rotating-item').eq(currentItem).fadeOut(fadeTime);
if (currentItem == numberOfItems - 1) {
currentItem = 0;
} else {
currentItem++;
}
$('.rotating-item').eq(currentItem).fadeIn(fadeTime);
}, itemInterval);
}
};
InfiniteRotator.init();
});