我在一个函数上有一个数组(allArr),来自allArr的位置0的第一个数组是来自另一个数组的位置0的图像,带有图像(命名图像)'原因是document.ready然后点击来自allArr的按钮(id =“nextimageandshuffle”)数组和来自图像数组的图像达到第五。我的问题是每次我点击下一个按钮我必须用空()div(id =“array”)清除其中来自allArr的数组添加了append(),但我不能在第5个数组后停止它,所以第5个图像(来自图像数组)仍然存在,但第5个数组(来自allArr)将其删除...
继承我的代码:
var allArr;
var contor = 0;
var i = 0;
$(document).ready( function() {
var arr = new Array("images/alfabet/w.png", "images/alfabet/f.png", "images/alfabet/v.png", "images/alfabet/a.png", "images/alfabet/b.png", "images/alfabet/p.png", "images/alfabet/o.png", "images/alfabet/r.png");
var baiat = new Array("images/alfabet/p.png", "images/alfabet/b.png", "images/alfabet/a.png", "images/alfabet/aa.png", "images/alfabet/i.png","images/alfabet/a.png", "images/alfabet/t.png");
var colac = new Array("images/alfabet/g.png", "images/alfabet/c.png", "images/alfabet/u.png", "images/alfabet/o.png", "images/alfabet/l.png", "images/alfabet/a.png", "images/alfabet/c.png");
var slapi = new Array("images/alfabet/s.png", "images/alfabet/ss.png", "images/alfabet/l.png", "images/alfabet/a.png", "images/alfabet/b.png", "images/alfabet/p.png", "images/alfabet/i.png", "images/alfabet/i.png");
var umbrela = new Array("images/alfabet/u.png", "images/alfabet/n.png", "images/alfabet/m.png", "images/alfabet/p.png", "images/alfabet/b.png", "images/alfabet/r.png", "images/alfabet/e.png", "images/alfabet/l.png", "images/alfabet/a.png");
allArr = new Array(arr, baiat, colac, slapi, umbrela);
for(i=0; i<allArr[0].length; i++)
{
var img = new Image();
img.src = allArr[0][i];
$('#array').append(img);
}
});
var image = new Array("images/baiat.png", "images/colac.png" , "images/slapi.png" , "images/umbrela.png");
var imgNumber=0;
var numberOfImg = image.length;
function nextImage(){
if(imgNumber < numberOfImg){
imgNumber++;
}
document.slideImage.src = image[imgNumber-1];
contor++;
$("#array").empty();
for(i = 0; i<allArr[contor].length; i++)
{
var img = new Image();
img.src = allArr[contor][i];
$('#array').append(img);
}
}
if(document.images){
var image1 = new Image();
image1.src = "images/vapor.png";
var image2 = new Image();
image2.src = "images/baiat.png";
var image3 = new Image();
image3.src = "images/colac.png";
var image4 = new Image();
image4.src = "images/slapi.png";
var image5 = new Image();
image5.src = "images/umbrela.png";
}
HTML:
<img src="images/vapor.png" name="slideImage" class='secondcanvas' width='450' height='300' alt="">
<div id="array" class='thirdcanvas'></div>
<a href="#" onClick="nextImage()"><img id="nextimageandshuffle" src="images/nextBtn.png" title="Continuare" ></a>
答案 0 :(得分:0)
不确定我是否真的明白你的问题是什么。但是,如果您想在调用div
后将最后一张图片保留在empty()
标记中,则只需再次附加该图片:
$("#array").empty();
var lastImage = new Image();
lastImage.src = allArr[4][4];
$("#array").append(lastImage);
请告诉我这是否有帮助。
答案 1 :(得分:0)
我不确定我是否完全明白你要做什么,但我想我明白了......
您需要确定自己是否在最后一张图片上,因为如果不是您还想要清空该元素。将当前图像src与allArr [4] [4]中的字符串进行比较,如果它们匹配,则不要执行.empty()。所以不只是:
$("#array").empty();
您需要将其替换为:
if(img.src == allArr[4][4]){
return;
}else{
$("#array").empty();
}