-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (29 loc) · 867 Bytes
/
Copy pathscript.js
File metadata and controls
33 lines (29 loc) · 867 Bytes
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
// Fetch data from JSON
fetch('data.json')
.then(response => response.json())
.then(data => {
const grid = document.querySelector('.grid');
// Create image elements
data.forEach(item => {
const gridItem = document.createElement('div');
gridItem.className = 'grid-item';
const img = document.createElement('img');
img.className = 'grid-image';
img.src = item.src;
img.alt = '';
img.loading = 'lazy';
gridItem.appendChild(img);
grid.appendChild(gridItem);
});
// Initialize Masonry after images load
imagesLoaded(grid, () => {
new Masonry(grid, {
itemSelector: '.grid-item',
columnWidth: '.grid-item',
percentPosition: true,
gutter: 20,
transitionDuration: '0.3s'
});
});
})
.catch(error => console.error('Error:', error));