Skip to content

Commit d586bcf

Browse files
committed
Fix animated heads display attempt 2
1 parent d3bc02d commit d586bcf

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

main.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
$.ajax({
2-
url: "./images/",
3-
success: data => {
4-
$(data).find("a").attr("href", (_i, filename) => {
5-
if (filename.match(/\.(jpe?g|png|gif)$/)) {
6-
$('body').append(
7-
"<div class=\"head-container\"><img class=\"head\" src=\"./images/" + filename + "\"/></div>"
8-
);
9-
}
10-
});
1+
fetch('https://api.github.com/repos/code4community/git-tutorial/git/trees/master')
2+
.then(response => response.json())
3+
.then(data => {
4+
const imagesUrl = data.tree.find(element => element.path === 'images').url
115

12-
let people = document.getElementsByClassName("head-container");
13-
for (let person of people) {
14-
person.style["animation-delay"] = -Math.floor(Math.random() * 1000) + "s"
15-
}
16-
}
17-
});
6+
fetch(imagesUrl)
7+
.then(response => response.json())
8+
.then(data => {
9+
const filenames = data.tree.map(element => element.path)
10+
11+
filenames.forEach(filename => {
12+
$('body').append(
13+
"<div class=\"head-container\"><img class=\"head\" src=\"images/" + filename + "\"/></div>"
14+
)
15+
})
16+
17+
const people = document.getElementsByClassName("head-container");
18+
for (let person of people) {
19+
person.style["animation-delay"] = -Math.floor(Math.random() * 1000) + "s"
20+
}
21+
})
22+
})

0 commit comments

Comments
 (0)