-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
103 lines (95 loc) · 2.85 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hour of Code Voting!</title>
<style>
* {
font-family: helvetica;
}
body {
width: 75vw;
margin: 0 auto;
margin-top: 50px;
}
#container {
display:flex;
flex-direction:row;
flex-wrap: wrap;
justify-content: /*flex-start | flex-end | center | space-between | space-around | center;*/center;
}
#container > div {
background-color: #eeeeee;
margin: 30px;
padding: 10px;
box-shadow: 5px 10px #aaaaaa;
border-radius: 0px;
}
img {
height: 130px;
}
p {
text-indent: 30px;
}
a {
margin: 20px;
}
</style>
</head>
<body>
<h1>Hour of Code Voting</h1>
<a href="http://bit.ly/northjamvoting">Vote Here! (as many times as you like)</a>
<div id="container"></div>
<script>
/*function init() {
var images = document.querySelectorAll('[data-src]')
document.addEventListener('scroll', function (event) {
console.log(images)
let imagesarr = []
for(let i = 0, ll = images.length; i != ll; imagesarr.push(images[i++]))
imagesarr.map ( (image) => {
if (isInViewport(image)) {
image.innerHTML = '<img src="' + image.getAttribute('data-src') + '">';
}
})
}, false);
}*/
const URL = 'https://api.myjson.com/bins/hnybw'
const TARGET = document.getElementById('container')
fetch(URL).then(resp => resp.json()).then(result => {
result = shuffle(result)
TARGET.innerHTML = result.map(([author, url, img]) =>
`<div>
<a href="${url}"><img src="${img}"></a>
<p>by ${author}</p>
</div>`
).join('')
//init()
})
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
var images = document.querySelectorAll('[data-src]');
var isInViewport = function (elem) {
var bounding = elem.getBoundingClientRect();
return (
bounding.top >= 0 &&
bounding.left >= 0 &&
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};
</script>
</body>
</html>