Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何用新的图像集替换图像集_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何用新的图像集替换图像集

Javascript 如何用新的图像集替换图像集,javascript,jquery,html,Javascript,Jquery,Html,在这里,我创建了一个图像滑块类的东西,最初有3个图像,点击pre/next按钮将替换prev-next图像 我想点击prev/next按钮应该完全用prev/next 3个图像(而不仅仅是一个)替换图像 var stPt=0,elToShow=10//显示10个元素 变量$ul=$('ul.ice navigator'); 变量$li=$('ul.ice-navigator li')//得到李的名单 var$copy_li=[]; var copy_lgt=$li.length-elToShow

在这里,我创建了一个图像滑块类的东西,最初有3个图像,点击pre/next按钮将替换prev-next图像

我想点击prev/next按钮应该完全用prev/next 3个图像(而不仅仅是一个)替换图像

var stPt=0,elToShow=10//显示10个元素
变量$ul=$('ul.ice navigator');
变量$li=$('ul.ice-navigator li')//得到李的名单
var$copy_li=[];
var copy_lgt=$li.length-elToShow;
//调用以根据设置的内容设置缩略图
initNav();
函数initNav(){
var-tmp;
对于(var i=elToShow;i<$li.length;i++){
tmp=每平方米(i)元;
$copy_li.push(tmp.clone());
tmp.remove();
}
}
$('.ice next')。单击(函数(){
$li=$('ul.ice-navigator li');//获取li的列表
//将第一个元素克隆移动到副本中的最后一个位置
$copy_li.splice(copy_lgt,0,$li.eq(0.clone());//array.splice(索引,数量,element1,…,elementX)
//杀死UL中的第一个元素
$li.eq(0).remove();
//添加到最后
$ul.append($copy_li.shift());
});
$('.ice-previous')。单击(函数(){
$li=$('ul.ice-navigator li');//获取li的列表
//将第一个元素克隆移动到副本中的最后一个位置
$copy_li.splice(0,0,$li.eq(elToShow-1.clone());//array.splice(索引,数量,element1,…,elementX)
//杀死UL中的第一个元素
$li.eq(elToShow-1).remove();
//添加到最后
$ul.prepend($copy_li.pop());
});


我该怎么做呢?

这里有一种方法

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

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());

});
$('.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();
    }
});