$(dragObjects).css("cursor", "pointer");
$(dragObjects).draggable({
containment:'#decor',
zIndex: 1000,
revert: true,
delay: 0,
dragDistance: 1000,
start: function(event, ui) {
dragTarget = event.currentTarget; // luam date despre obiectul curent tras
indexDrags = dragObjects.indexOf(dragTarget); // afiseaza index-ul obiectului tras
returnSrc = $(dragTarget).children("img").prop("src");
p = $(dragTarget).children("p").html();
}
});
$(dropObjects).droppable({
drop: function( event, ui )
{
dropTarget = event.target.id; // luam date despre drop target
indexDrops = dropTarget.charAt(dropTarget.length-1); // afiseaza index-ul dropTarget-ului
var obj = $("#" + dropTarget).children("img");
obj.prop("src", returnSrc);
$("#" + dropTarget).append("<p class='texts'>" + p + "</p>");
$(dropObjects[indexDrops]).droppable('disable');
$(dragTarget).css("visibility", "hidden");
DropAmount++;
if (indexDrags != indexDrops){
wrongDropAmount++;
toChange.push(indexDrops);
toChange.sort();
console.log("to change: " + toChange);
}
else{
finalArray.push(indexDrops);
finalArray.sort();
console.log("final array: " + finalArray);
}
if(DropAmount == 6){
checkBtn.disabled = false;
}
}
});
};
function checkAnswer(){
DropAmount = DropAmount - wrongDropAmount;
wrongDropAmount = 0;
for(var i=0; i<finalArray.length; i++){
for(var i=0; i<correctAnswers.length; i++){
if(finalArray[i] == correctAnswers[i]) {
$("#screenPartner").prop("src", "res/pixiDreapta.svg");
$("#porumbel").prop("src", "images/happyPigeon.svg");
$("#linieFinal").css("visibility", "visible");
resetBtn.disabled = false;
checkBtn.disabled = true;
updateBubble(2);
}
else{
revert();
checkBtn.disabled = true;
$("#screenPartner").prop("src", "res/pixiDreaptaTrist.svg");
$("#porumbel").prop("src", "images/sadPigeon.svg");
toChange = [];
updateBubble(3);
}
}
}
};
function revert(){
for(var i=0; i < toChange.length; i++){
if (toChange[i] == correctAnswers){
$("#dropspot" + toChange[i]).children("img").prop("src", "images/drop.svg");
$(dropObjects[toChange[i]]).children("p").hide();
$(dragObjects[toChange[i]]).css("visibility", "visible");
$(dropObjects[toChange[i]]).droppable('enable');
}
}
return true;
};
正确的顺序是数组var correctAnswers = [0,1,2,3,4,5];并且改变存储错误索引的数组,最终数组存储正确定位的图像索引。
我需要什么:当图像定位正确以从checkanswer功能获得正确的反馈时,如果某些图像没有正确定位则是另一个,所以应该还原和其他一些东西。我在编写代码时错了吗?