Is it possible to toggle between thumbnails and a larger image in a jQuery gallery?

Hello, I am new to website development and I would like to create a jquery based photo gallery for my personal website. One feature that really catches my eye is this one (for example):

The gallery has a large thumbnail grid where you can click on a thumbnail to open a slideshow of the larger images. From the slideshow view, there is an option to switch back to the thumbnails by clicking on a dedicated icon. I believe this type of gallery is jquery-based, but I am unsure about how the transition between thumbs and slideshow is achieved... possibly using css3 key-frames?

I don't want to copy the gallery, just replicate this functionality. Any tips on how I can get started would be greatly appreciated.

Thank you in advance

Answer №1

This script I just created will help you get started.

To organize the images into neat rows, I am utilizing the column-count property on the parent element. Currently set to 3 rows, this value can be adjusted as needed.

(For the slideshow feature, that part is open for customization. There are numerous tutorials and plugins available for creating slideshows.)

The clicked img tag's source is captured and converted into a variable within the script. This variable is then applied to the overlay class using the .css() method. This enables an overlay effect for each image that is clicked.

The Structure of HTML:

<div class="parent">
    <img src="urlGoesHere" alt="img" />
    <!-- Add more images here -->
</div>

The CSS Styling:

.parent {
    width: 100%;
    column-count: 3; /* determines the number of columns */
    -webkit-column-count: 3;
    -moz-column-count: 3;
    -o-column-count: 3;
    -ms-column-count: 3;
    column-gap: 5px; /* sets the spacing between columns */
    -webkit-column-gap: 5px;
    -moz-column-gap: 5px;
    -o-column-gap: 5px;
    -ms-column-gap: 5px;
    position: relative;
    z-index: 10;
}

The Script:

$('.parent img').on('click', function() {
   var imgSrc = $(this).attr('src'); // Stores the src attribute in a variable

    $('.overlay').fadeIn().css('background-image', 'url(' + imgSrc + ')'); // Displays the overlay with the selected image and fades it in

    $('.close').on('click', function() { // Functionality for the close button
        $('.overlay').fadeOut(); // Hides the overlay upon clicking
    });
});

Check out the demo on JSFiddle: Demo

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that the user remains within the current div when they click the submit button, even if the textbox is

For the past 48 hours, I've been grappling with an issue on my HTML page that features four divs. Each div contains three input fields and a button. The problem arises when a user leaves a text box empty upon submitting - instead of staying in the sam ...

Exponential calculator in Javascript

I'm working on a basic calculator project using html5, css3 and javascript. However, I've run into an issue with the exponent button not functioning properly. Here's my code snippet: <html> <head> <meta charset = "utf-8" ...

The jQuery function $.post fails to include information about which button was clicked in the request

I've encountered a problem where $.post isn't sending information about which button was pressed in my form. The scenario is having a form with two buttons: <form method="post" action="/home/index"> <input type='hidden' n ...

After each alert triggers a page refresh, it should not automatically refresh. To prevent the refresh, I implemented a preventDefault function that works seamlessly in Chrome but not

My code is experiencing an issue where event.preventDefault() works in Chrome, but not in Firefox. I have tried both methods and searched for solutions, but nothing seems to be working. If needed, I can post all of my code if the error cannot be found. fu ...

Disappearing Cloned Form Fields in jQuery

Hey there! I'm trying to duplicate a section of a form using the code below. But for some reason, the copied fields are only visible for a split-second before they disappear. Can anyone spot any errors that might be causing this strange behavior? jQu ...

Utilizing Robot Framework to select CSS attributes

The Selenium documentation provides an example of how to use Get Element Attribute: ${id}= Get Element Attribute css:h1 id However, I encountered a problem with this selector: ${VISIBILITY}= Get Element Attribute css:visibility mySidebar I ...

Can the z-index of a div be altered by a checked checkbox?

I've been trying to figure out how to make a PayPal button only clickable after the user confirms the Terms of Service. My idea is to place another div over the PayPal button with an unchecked checkbox, opacity, and z-index. When the user checks the c ...

Formatting text over an image

The challenge I am facing involves having an image and text on it in two separate divs with a background color. The length of the text in one div is long while the text in the second div is short, but I want to ensure that the width of both divs are equal. ...

What is preventing ShowViaLink() from functioning properly in Firefox and Internet Explorer?

I am facing an issue with my webpage where the navigation does not work on Firefox or IE, but it works perfectly fine on Chrome. I suspect that the problem lies in this code, as when I made changes to it, the navigation stopped working on Firefox & IE: ...

What is the best way to align my grid cells to the center?

I'm facing an issue where the grid cells do not move closer together as I resize the window, instead they just stay in their place. I want to achieve a similar layout to . To share my project code, I have uploaded it on codepen: https://codepen.io/Ale ...

CSS - using numbers to create dynamic background images

I am looking to create a design where the background images in CSS display increasing numbers per article, like this example: This idea is similar to another post on Stack Overflow discussing using text as background images for CSS. You can find it here: ...

Using Jquery to run a jquery script stored in a variable within jQuery syntax

This question may seem a bit confusing, so allow me to explain further. I am trying to execute a jquery script that is written in a text file obtained through an ajax request. For example, the code I receive from the ajax request looks like this: ($($(" ...

Switching the class again does not result in an icon change

When a button is clicked, a class of "fa-minus" is added to a newly appearing div. If the fa-minus class is then clicked, the text decoration changes to a "line-through". Additionally, I want the fa-minus icon to change to fa-plus (which will undo the line ...

Utilizing AJAX to upload a file and managing it through a Java servlet on the server side

I've been struggling with this particular issue for the past few days and haven't found any helpful resources elsewhere. I'm attempting to upload a file through an HTML form that includes other input fields: var formData = new FormData() ...

Troubleshooting issue with jquery.backgroundSize.js on Internet Explorer 8

After trying out the jquery.backgroundSize.js plugin, I ran into issues getting it to work in IE8. I followed the steps from the official website and tested on various browsers like IE9 and Firefox, but nothing seemed to happen on IE8. css: #main{ b ...

Concealing and wrapping text using CSS in a table structure

My table is displayed below: <table style="width: 100%; white-space: nowrap; overflow: hidden;"> <tbody><tr> <th> Department </th> <th> Function </th> ...

The function $.ajax({}) is not recognized in the Django framework

I have been searching for a solution to this specific problem, but none of the related questions I found were able to help. There must be another reason why it's not working, but I'm finding it difficult to pinpoint the issue. Here is the code sn ...

I aim to toggle the visibility of input fields upon clicking a button

Form.html <form [formGroup]="myForm"> <ion-button [(ngModel)]="isActive"(click)="onClick()" >Add</ion-button> <ion-item> <ion-label position="floating">First Name</ion-label&g ...

Despite following the instructions in the manual, the jquery code completion feature in Netbeans is not functioning as expected

Hello there, I've been trying to get jQuery code completion to work based on the information I found on various help pages. Here's what I did: Checked if my targeted browser was correct (I chose Firefox 3.x or later) Added the jQuery file into ...

Ajax refreshes page to default state post search

I have implemented a live search feature that retrieves relevant information from the database and displays it in a table using Ajax to avoid page refresh. Currently, after each search, the results reset back to nothing until another input is received. How ...