如何将图像集替换为新的图像集

How to replace image set with new set of images

本文关键字:图像 替换      更新时间:2023-09-26

在这里,我最初创建了一个包含 3 张图像的图像滑块,其中单击上一个/下一个按钮将替换上一个下一个图像。

我想点击上一个/下一个

按钮应该用上一个/下一个 3 个图像(不仅仅是一个)完全替换图像。

var stPt = 0, elToShow = 10; //showing 10 elements
var $ul = $('ul.ice-navigator');
var $li = $('ul.ice-navigator li'); //get the list of li's
var $copy_li = [];
var copy_lgt = $li.length - elToShow;
//call to set thumbnails based on what is set
initNav();
function initNav() {
var tmp;
for (var i = elToShow; i < $li.length; i++) {
  tmp = $li.eq(i);
  $copy_li.push(tmp.clone());
  tmp.remove();
  }
}
$('.ice-next').click (function () {
$li = $('ul.ice-navigator li'); //get the list of li's
//move the 1st element clone to the last position in copy_li
$copy_li.splice(copy_lgt, 0, $li.eq(0).clone() );          //array.splice(index,howmany,element1,.....,elementX)
//kill the 1st element in the UL
$li.eq(0).remove();
//add to the last
$ul.append($copy_li.shift());
});
$('.ice-previous').click (function () {
$li = $('ul.ice-navigator li'); //get the list of li's
//move the 1st element clone to the last position in copy_li
$copy_li.splice(0, 0, $li.eq(elToShow-1).clone()); //array.splice(index,howmany,element1,.....,elementX)
//kill the 1st element in the UL
$li.eq(elToShow-1).remove();
//add to the last
$ul.prepend($copy_li.pop());
});

http://jsfiddle.net/devsvits/hV5DA/

我该怎么做?

这是一种方法...

您将高级代码粘贴到函数中,并根据需要前进的图像多次调用它。

http://jsfiddle.net/hV5DA/1/

$('.ice-next').click (function () {
  function nextItem(){
        $li = $('ul.ice-navigator li'); //get the list of li's
       //move the 1st element clone to the last position in copy_li
        $copy_li.splice(copy_lgt, 0, $li.eq(0).clone() ); //array.splice(index,howmany,element1,.....,elementX)
        //kill the 1st element in the UL
        $li.eq(0).remove();
        //add to the last
        $ul.append($copy_li.shift());
  } 
    //number of items to replace   
    var numItemsToAdvance = 3;    
    //call function n times
    while(numItemsToAdvance--){
        nextItem();
    }
});