Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ <h1>Interactive Photo Gallery</h1>

<section id="gallery" class="gallery">
<!-- Photos will be dynamically added here -->

<img src="https://plus.unsplash.com/premium_photo-1673292293042-cafd9c8a3ab3?q=80&w=987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This homework was intended to not edit the HTML, but to use the photos array to create <img/> in javascript using document.createElement('img'). You should edit this submission to do that.

<img src="https://images.unsplash.com/photo-1472396961693-142e6e269027?q=80&w=952&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://images.unsplash.com/photo-1482938289607-e9573fc25ebb?q=80&w=987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://images.unsplash.com/photo-1509316975850-ff9c5deb0cd9?q=80&w=987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?q=80&w=944&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://images.unsplash.com/photo-1519501025264-65ba15a82390?q=80&w=1064&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://images.unsplash.com/photo-1496568816309-51d7c20e3b21?q=80&w=1031&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://images.unsplash.com/photo-1494522855154-9297ac14b55f?q=80&w=1170&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://plus.unsplash.com/premium_photo-1669725687221-6fe12c2da6b1?q=80&w=987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://plus.unsplash.com/premium_photo-1666278379770-440439b08656?q=80&w=988&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://images.unsplash.com/photo-1441057206919-63d19fac2369?q=80&w=987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://images.unsplash.com/photo-1535268647677-300dbf3d78d1?q=80&w=987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D">
<img src="https://media.istockphoto.com/id/1154370446/photo/funny-raccoon-in-green-sunglasses-showing-a-rock-gesture-isolated-on-white-background.jpg?s=612x612&w=0&k=20&c=kkZiaB9Q-GbY5gjf6WWURzEpLzNrpjZp_tn09GB21bI=">
<img src="https://cdn.pixabay.com/photo/2014/10/01/10/44/animal-468228_640.jpg">
</section>

<div class="load-more">
Expand Down
74 changes: 73 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,78 @@ const photos = [
url: 'https://images.unsplash.com/photo-1535268647677-300dbf3d78d1?q=80&w=987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
type: 'animals',
},
{
url: 'https://media.istockphoto.com/id/1154370446/photo/funny-raccoon-in-green-sunglasses-showing-a-rock-gesture-isolated-on-white-background.jpg?s=612x612&w=0&k=20&c=kkZiaB9Q-GbY5gjf6WWURzEpLzNrpjZp_tn09GB21bI=',
type: 'animals',
},
{
url: 'https://cdn.pixabay.com/photo/2014/10/01/10/44/animal-468228_640.jpg',
type: 'animals',
},
];

console.log('hello');
// Week_3_Work
const gallery = document.querySelector('.gallery'); //selecting the gallery section using its class
const buttons = document.querySelectorAll('.filter-buttons button');
let activePhotoCount = 6;
const loadMoreButton = document.querySelector('#loadMore');

//go through photos array
photos.forEach((photo) => {
const imgEl = document.createElement('img');
imgEl.src = photo.url
imgEl.classList.add(photo.type, 'photo');
imgEl.style.display = 'none';

gallery.appendChild(imgEl);
});

const allPhotos = document.querySelectorAll('.photo')
const allPhotosArray = [...allPhotos];

allPhotosArray.slice(0, activePhotoCount).forEach(photo => {
photo.style.display = 'block';
});

function showInitialPhotos() {
allPhotosArray.forEach(photo => photo.style.display = 'none');
allPhotosArray.slice(0, activePhotoCount).forEach(photo => {
photo.style.display = 'block';
});
}

// Initial load of photos
showInitialPhotos();


loadMoreButton.addEventListener('click', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This button is not working as expected. You should double-check why this is not working.

activePhotoCount +=6;
allPhotosArray.slice(0, activePhotoCount).forEach(photo => {
photo.style.display = 'block';
});
if (activePhotoCount >= allPhotosArray.length) {
loadMoreButton.style.display = 'none';
}
});

buttons.forEach((button) => {
button.addEventListener('click', (event) => {
const type = event.target.id;
const filteredPhotos = type === 'all'
? allPhotosArray
: allPhotosArray.filter(photo => photo.classList.contains(type));

//Resetting
activePhotoCount = 6;
gallery.innerHTML = '';

filteredPhotos.slice(0, activePhotoCount).forEach(photo => {
gallery.appendChild(photo);
photo.style.display = 'block';
});

loadMoreButton.style.display = filteredPhotos.length > activePhotoCount ? 'block' : 'none';

activePhotoCount = 6;
});
});
1 change: 1 addition & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ h1 {

.load-more button:hover {
background-color: #218838;
text-align: center;
}