Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (60 loc) · 1.75 KB
/
Copy pathscript.js
File metadata and controls
67 lines (60 loc) · 1.75 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
(function ($) {
var chosenArtist,
userData={};
/**
* Loads data from the API.
*/
function loadData() {
$.ajax({
url: "data.json",
method: 'GET',
dataType: 'json',
success: function(result){
onLoadData(result);
},
error: function(err) {
console.log('err', err)
}
});
};
/**
* Receives data from the API, creates HTML for images and updates the layout
*/
function onLoadData(data) {
$.each(data, function(i, value) {
$('.grid section').append($('<div>').attr('class','grid-item').append($('<img>').attr('src',value.photoUrl)).append($('<div>').attr('class','artistInfo').append($('<div>').append($('<p>').text(value.bio)))));
});
var $grid = $('.grid').imagesLoaded( function() {
// init Packery after all images have loaded
$grid.packery({
itemSelector: '.grid-item',
percentPosition: true
});
});
function animate() {
getNewData();
$('.grid section:first').remove();
$("body").animate({scrollTop: $(document).height()}, 30000, animate);
}
animate()
};
function getNewData(){
$.ajax({
url: "data.json",
method: 'GET',
dataType: 'json',
success: function(data){
$newSection = $('<section>');
$.each(data, function(i, value) {
$newSection.append($('<div>').attr('class','grid-item').append($('<img>').attr('src',value.photoUrl)).append($('<div>').attr('class','artistInfo').append($('<div>').append($('<p>').text(value.bio)))));
});
$('.grid').append($newSection).packery('appended', $newSection);
},
error: function(err) {
console.log('err', err)
}
});
}
// Load first data from the API.
loadData();
})(jQuery);