Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·75 lines (69 loc) · 2.38 KB
/
Copy pathscript.js
File metadata and controls
executable file
·75 lines (69 loc) · 2.38 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
68
69
70
71
72
73
74
75
let switching = false;
function updateGallery() {
$('.gallery__core img, .gallery__bg img').attr('src',galleryItems[0].url);
$('.gallery__track').empty();
$.each(galleryItems,function(index,item){
$('.gallery__track').append('<div class="gallery__track__item '+(index==0 ? 'active' : '')+'"><img src="'+item.thumb+'" data-full="'+item.url+'" alt=""></div>');
});
}
function getNewImages() {
(async () => {
const response = await fetch('https://api.github.com/repos/jjdengjj/jjdengjj.github.io/contents/gallery');
const data = await response.json();
let items = [];
for (let file of data) {
let newItem = {
id: file.name,
url: "https://www.rand2ai.org/gallery/".concat(file.name),
thumb: "https://www.rand2ai.org/gallery/".concat(file.name)
}
items.push(newItem);
}
galleryItems = items;
updateGallery();
})();
}
// $('.gallery__search input').on('keyup',debounce(() => getNewImages()));
$('.gallery__track').on('click','.gallery__track__item',function(){
if (!switching) {
switching = true;
$(this).addClass('active').siblings().removeClass('active');
// animate in new core image and background image
const $oldBGImg = $('.gallery__bg img');
const $oldImg = $('.gallery__core img');
const newImg = $(this).find('img').data('full');
const $newImg = $('<img class="slide-in" src="'+newImg+'">');
const $newBGImg = $('<img class="fade-in" src="'+newImg+'">');
$('.gallery__core').append($newImg);
$('.gallery__bg').append($newBGImg);
setTimeout(function(){
$newImg.addClass('shift-up');
$oldImg.addClass('shift-up');
$oldBGImg.addClass('fade-out');
$newBGImg.addClass('fading');
setTimeout(function(){
$('.gallery__core img').eq(0).remove();
$('.gallery__bg img').eq(0).remove();
$('.slide-in').removeClass('slide-in shift-up');
$('.fade-in').removeClass('fade-in fading');
switching = false;
},400);
},10);
}
});
let galleryItems = [
{
id:'None',
url: "https://www.rand2ai.org/img/favicon.ico",
thumb: "https://www.rand2ai.org/img/favicon.ico"
}
];
getNewImages();
updateGallery(); // once on load
// function debounce(func, timeout = 300){
// let timer;
// return (...args) => {
// clearTimeout(timer);
// timer = setTimeout(() => { func.apply(this, args); }, timeout);
// };
// }