A jquery plug-in every day-Jiugongge puzzle 2
Jiugongge Jigsaw 2
I always feel that my puzzle has a lack of function. After thinking about it later, it seems that the function of judging whether to win has not been done, and then I added it.
The effect is as follows
Code part
function success(){
var flag = true;
$(".item").getarr().forEach(item=>{
var index = item.attr("data-index");
if(!item.hasClass("i"+index)){
flag =false;
}
})
if(flag){
alert("success!")
}
}
Idea explanation
- In fact, each tile has two attributes. One is to indicate which tile it is, and the other is to indicate where it is now. When they overlap, it means that the tile is in the correct position. , So it is to check every time after the action is completed, if all the tiles are in the correct position, it is completely restored
- Finish, rest