I have a photo gallery where I show only 5 pictures at first. When someone clicks a button, I want the remaining photos to appear with a smooth sliding effect.
Right now my page loads just a few photos from the database. I need help figuring out how to make the other pictures show up when someone clicks a button. The new photos should slide down smoothly.
Here’s what I’m trying to do:
// Initial photo loading
$query = "SELECT photo_url FROM user_photos WHERE user_id = ? LIMIT 5";
$stmt = $pdo->prepare($query);
$stmt->execute([$userId]);
$photos = $stmt->fetchAll();
foreach($photos as $photo) {
echo '<img src="' . $photo['photo_url'] . '" class="gallery-image">';
}
$('#load-more-btn').click(function() {
// Need code here to load and slide down remaining photos
});
What’s the best way to fetch the extra images and animate them sliding down? Should I use AJAX to get the remaining photos from MySQL?