-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
146 lines (129 loc) · 3.49 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
142
143
144
145
146
<!DOCTYPE html>
<html>
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
}
.header {
text-align: center;
padding: 32px;
}
.row {
display: -ms-flexbox; /* IE 10 */
display: flex;
-ms-flex-wrap: wrap; /* IE 10 */
flex-wrap: wrap;
padding: 0 4px;
}
/* Create two equal columns that sits next to each other */
.column {
-ms-flex: 50%; /* IE 10 */
flex: 50%;
padding: 0 4px;
}
.column img {
margin-top: 8px;
vertical-align: middle;
}
/* Style the buttons */
.btn {
border: none;
outline: none;
padding: 10px 16px;
background-color: #f1f1f1;
cursor: pointer;
font-size: 18px;
}
.btn:hover {
background-color: #ddd;
}
.btn.active {
background-color: #666;
color: white;
}
</style>
<body>
<!-- Header -->
<div class="header" id="myHeader">
<h1>Image Grid</h1>
<p>Click on the buttons to change the grid view.</p>
<button class="btn" onclick="one()">1</button>
<button class="btn active" onclick="two()">2</button>
<button class="btn" onclick="four()">4</button>
</div>
<!-- Photo Grid -->
<div class="row">
<div class="column">
<img src="swedish-playground.png" style="width:100%">
<img src="the-millenium-falcon.png" style="width:100%">
<img src="tiny-tiger.png" style="width:100%">
<img src="vader-vs-obi-won.png" style="width:100%">
<img src="the-squad.png" style="width:100%">
<img src="x-speedster.png" style="width:100%">
<img src="kickflip.png" style="width:100%">
</div>
<div class="column">
<img src="super-tank-1000.png" style="width:100%">
<img src="x-team-poster.png" style="width:100%">
<img src="x-wing.png" style="width:100%">
<img src="zack.png" style="width:100%">
<img src="telekenisis-boy.png" style="width:100%">
<img src="stormtrooper-red.png" style="width:100%">
</div>
<div class="column">
<img src="stormtrooper-blue.png" style="width:100%">
<img src="electric-current.png" style="width:100%">
<img src="experiment.png" style="width:100%">
<img src="b-wing.png" style="width:100%">
<img src="anton-helga.png" style="width:100%">
<img src="master-flaster.png" style="width:100%">
<img src="One-Eye-Laser.png" style="width:100%">
</div>
<div class="column">
<img src="santa-fe.png" style="width:100%">
<img src="r2d2.png" style="width:100%">
</div>
</div>
<script>
// Get the elements with class="column"
var elements = document.getElementsByClassName("column");
// Declare a loop variable
var i;
// Full-width images
function one() {
for (i = 0; i < elements.length; i++) {
elements[i].style.msFlex = "100%"; // IE10
elements[i].style.flex = "100%";
}
}
// Two images side by side
function two() {
for (i = 0; i < elements.length; i++) {
elements[i].style.msFlex = "50%"; // IE10
elements[i].style.flex = "50%";
}
}
// Four images side by side
function four() {
for (i = 0; i < elements.length; i++) {
elements[i].style.msFlex = "25%"; // IE10
elements[i].style.flex = "25%";
}
}
// Add active class to the current button (highlight it)
var header = document.getElementById("myHeader");
var btns = header.getElementsByClassName("btn");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function() {
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
});
}
</script>
</body>
</html>