-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex1.html
More file actions
70 lines (62 loc) · 1.89 KB
/
index1.html
File metadata and controls
70 lines (62 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Adventure time turning cards</title>
<script src="scripts/jquery.js"></script>
<script>
var boxFlipped=0;
var flippedImage=new Array(2);
var imagePath=new Array(18);
for(i=0; i<36; i++){
if (i < 18) imagePath[i]="images\/"+(i+1)+".png";
else imagePath[i]="images\/"+(i-17)+".png";
}
$( document ).ready( function() {
confuseArray(imagePath);
for(i=0; i<36;i++){
$(".wrapper").append("<div id="+i+" class='box'><img id='img"+i+"' class='img' src="+imagePath[i]+">")
}
$( ".box" ).click( function() {
console.log("you've just clicked button with id:"+$(this).attr('id'));
if($( "#img"+$(this).attr('id') ).css("visibility")=="hidden" && boxFlipped<2){
flippedImage[boxFlipped] = $( "#img"+$(this).attr('id') );
$( "#img"+$(this).attr('id') ).css("visibility","visible");
boxFlipped++;
if ( flippedImage[0].attr('src')==flippedImage[1].attr('src') ) boxFlipped =0;
} else {
flippedImage[0].css("visibility","hidden");
flippedImage[1].css("visibility","hidden");
boxFlipped = 0;
}
})
})
function confuseArray(array){
var a,b,r1,r2;
for(i=0; i<array.length; i++){
r1=Math.floor(Math.random()*array.length);
r2=Math.floor(Math.random()*array.length);
a = array[r1];
b = array[r2];
array[r1] = b;
array[r2] = a;
}
return array;
}
</script>
<style>
.wrapper { width:920px; margin:0 auto; }
.box { width:150px; height:150px; float:left; margin:1px; color: #333; background:#333;}
.img {
visibility: hidden;
width: 150px;
height: 150px;
}
.col1 { background:yellow; }
.col2 { background:red; }
</style>
</head>
<body>
<div class="wrapper"> </div>
</body>
</html>