-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
141 lines (126 loc) · 3.08 KB
/
index.html
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<html>
<head>
<meta charset="utf-8">
<title>Gritted Grid</title>
<style>
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
html, body {
font-family: Georgia, Serif;
font-size: 20px;
background-color: #333;
}
h1 {
font-size: 2rem;
color: #ddd;
}
#grid {
position: relative;
width: 100%;
overflow: hidden;
}
.cell, .colorbox {
float: left;
cursor: pointer;
background-color: #444;
width: 150px;
height: 150px;
margin: 10px;
}
#filters .colorbox {
position: relative;
top: -1em;
width: 40px;
height: 30px;
}
#grid .colorbox {
pointer-events:none;
}
#filters label {
float: left;
color: #ddd;
}
.papayawhip { background-color: papayawhip; }
.darkseagreen { background-color: darkseagreen; }
.sienna { background-color: sienna; }
.tomato { background-color: tomato; }
.indianred { background-color: indianred; }
.orange { background-color: orange; }
.orangered { background-color: orangered; }
#filters .selected {
border: 2px solid #ddd;
}
</style>
<script charset="utf-8" src="lib/plugins/Modernizr.min.js"></script>
</head>
<body>
<h1>This Grid is gritted</h1>
<div id="filters">
<label>Click on a colour to filter</label>
<div class="colorbox"></div>
</div>
<div id="grid">
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
window.jQuery || document.write(
'<script src="lib/jquery-1.10.2.min.js"><\/script>'
);
</script>
<script>
yepnope({
test: Modernizr.csstransitions,
yep: ["lib/plugins/jquery.transit.min.js"],
callback: function () {
$.fn.animate = $.fn.transition;
console.log("Now using CSS transitions");
}
});
</script>
<script src="js/jquery.gritted.js"></script>
<script src="js/jquery.gritted.filters.js"></script>
<script>
var $grid = $("#grid"),
$filterBox = $("#filters"),
cols = Math.floor($(window).width() / 170),
rows = 4,
colors = ["papayawhip", "darkseagreen", "sienna",
"tomato", "indianred", "orange", "orangered"];
// One coloured box to filter
for (var i=0; i<colors.length; i++) {
$("<div>")
.addClass("colorbox " + colors[i])
.appendTo($filterBox);
}
for (i=0; i<rows*cols; i++) {
$("<div>")
.addClass("colorbox " + colors.random())
.appendTo($grid);
}
// Create the 'grit' with the holes pattern
$grid.gritted({
holes: "A3, A5, B2, B4, B6, C3, C4, C5, D4, E4, F2, F3, F4, F5, F6",
filterAnimation: "random",
filteredClass: "filtered",
cols: cols,
rows: rows
});
// filter elements of the choosen color
$filterBox.on("click", ".colorbox", function(evt) {
if ($(this).hasClass("selected")) return;
var className = this.className.replace("colorbox", "").trim();
$grid.data("gritted").filter(className);
$filterBox.children()
.removeClass("selected")
.filter("." + className).addClass("selected");
});
$grid.on("click", ".cell", function(evt) {
$(this).data("grid-position")
.toggleHole();
});
</script>
</body>
</html>