Guide on displaying gallery images when clicking on a specific class

I am in the process of developing a gallery tab for a website, initially displaying three thumbnails. The goal is to reveal the remaining thumbnails when a class named show-all is clicked. I have successfully animated the gallery's height to show the hidden content. However, I am encountering an issue where even after hiding the excess thumbnails using overflow:hidden, parts of the second row are still visible. I want them completely hidden. Below is my code block:

HTML

<div class="gallery">
     <h3>Photos</h3>
 <a class="see-all" href="javascript:void(0)">See All</a>
    <div class="clear"></div>
    <div class="row">
        <div class="col-xs-4">
            <div class="thumbnail">
                <img src="http://placekitten.com/g/150/150">
            </div>
        </div>
        <div class="col-xs-4">
            <div class="thumbnail">
                <img src="http://placekitten.com/g/150/150">
            </div>
        </div>
        (remaining thumbnail divs here)
    </div>
</div>

Jquery

$('.see-all').click(function(){
    $(this).parents('.gallery').animate({height: $(".gallery").get(0).scrollHeight}, 1000);
});

Any assistance would be greatly appreciated.

DEMO

NOTE: I am unable to change the height of the gallery due to variations in image sizes.

Answer №1

Instead of depending on manipulating the gallery height, you can opt to display only the first 3 images and hide the rest... This way, you won't have to worry about maintaining image heights.

Clicking on see all will then reveal the remaining images.

Check out the JS BIN example: http://jsbin.com/qoliqukoye/1/edit?html,js,output

        $(document).ready(function(){
            var x = 0;
            $('.row').children().each(function () {
                if (x >= 3) {
                    $(this).hide();
                }
                x++;
            });
            $(".see-all").click(function(){
                $('.row').children().fadeIn('slow');
            });
        });

Answer №2

To achieve this effect, simply assign a class to the first three visible elements and hide all other thumbnails except those. Update the JavaScript code as shown below:

$('.see-all').click(function(){
  $(this).parents('.gallery').animate({height:'810px'});
  $('.thumbnail').show();
});

For a demonstration, refer to the following example: http://jsfiddle.net/wvzyzLo1/1/

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

Problem with AWS Lambda function handler failing to insert data into Athena

Trying out a sample code snippet for Amazon Athena to test data insertion, but it's not working as expected. The CloudWatch logs don't show any output after the statement execution is completed. Even when switching to a simple select statement, t ...

Unable to link JSON response to input field using jQuery AJAX (MVC 4)

I am facing an issue with binding JSON values to a text box. Despite searching online, I haven't been able to find a solution for this. Here is the code that I am using: JQuery: $(document).ready(function () { $('#Email').mousemove(functio ...

Sorting through a list post a retrieval action

Could you guys please help me understand why my code is not functioning properly? I am receiving an array from my backend rails API, which is providing the data correctly. I have created an empty array where I filter the records based on their ID. The fi ...

CSS animations are failing to work properly in Firefox due to a pseudo-element issue

I'm encountering a problem with my CSS animations in Firefox. Specifically, the animations are not working on a pseudo element (:after) while they work perfectly fine on other browsers. Below is where the animations are being applied: :after { d ...

What is the most effective method for developing HTML with PHP or Jquery?

My JavaScript Object contains some important information that I need to display. I have two possible options for generating the HTML from this object. I am unsure which method is the most appropriate, or if it is simply a matter of personal preference. 1 ...

A guide to building a versatile dropdown component with Material UI or MUI in a React application

Is there a way to create a reusable dropdown component using Material UI or MUI in React? ...

What is the best way to extract user input and pass it to an AJAX request URL?

Recently, I successfully completed an AJAX request using AngularJS. You can check out the code here. Everything was working perfectly until I tried to add a dynamic variable (city) to the link like this: $http.get('http://api.wunderground.com/api/KEY ...

The process of sharing information between JavaScript classes

I'm struggling to grasp the concept of object-oriented JavaScript, particularly in terms of how classes can communicate with each other. Let's consider an example using Babel: We have a "ColorPalette" class that contains a list of colors We also ...

Transform nested JSON objects into a JSON array using JavaScript

Hey there! I've got this JSON structure that I'm trying to convert into an array without having to iterate over each element. Is there a JavaScript function that can help me achieve this? { "ES": { "130": { "code": "A Coruсa", ...

MUI Input component does not support the use of the oninput attribute

My MUI Input component is defined like this, but the oninput attribute doesn't seem to work in MUI: <Input variant="standard" size="small" type="number" inputProps={{ min: '0', o ...

404 error occurs when attempting to load SVG files in Webpack 2

Recently, I delved into the world of webpack. However, I encountered a problem when trying to load an SVG file referenced in one of my CSS files. Despite trying various loaders such as this, that, and the other, I keep receiving a 404 error. Can anyone pro ...

What are the steps to installing and utilizing the Chart.js package on your local machine?

I thought installing chart.js on my Raspberry Pi would be a simple task, but I seem to be struggling with it. Due to the nature of my project, I need to have it installed locally rather than relying on an online version. Following the usual steps, I navig ...

Encountering an error with an unknown variable while attempting to access a value from a JSON object

I had second thoughts about asking this question for fear of receiving a down-vote, but after extensive research and hours of typing, I have decided to go ahead. My goal is to retrieve the values 37 and exampleoffice from a json object: {"officeId":37,"o ...

Why is Vue Router Navigation Guard throwing an error about exceeding the maximum call stack size?

Encountering a recurring issue of maximum stack size exceeded while implementing the following code for vue router navigation guards per-route: import state from "../vuex-store/state.js"; import Editor from "../views/Editor"; const routes = [ { ...

Tips for arranging divs in a row to switch to stacking when the screen size decreases

Sorry if this question seems repetitive, but as a newbie, deciphering posts from others has been overwhelming! I have two divs placed side by side within a wrapper, but I need them to stack on top of each other when viewed on a tablet or phone. Below is t ...

Adjust the x-axis on the Vue.js bar chart

I'm currently working on a Vue.js Laravel application where I am trying to incorporate a bar chart using the ApexCharts module. <apexchart ref="apexChart" :options="chartOptions" :series="chartData" type="bar" ...

Transition one background image into another using background positioning

Snippet of code: https://jsfiddle.net/foy4m43j/ HTML: <div id="background"></div> CSS: #background { background-image: url("http://i.imgur.com/hH9IWA0.png"); background-position: 0 0; background-repeat: repea ...

What are the potential drawbacks of utilizing <div> spacers in web design?

Is it considered poor practice to utilize <div> elements as a means of creating space between other elements? If so, what are the reasons behind this? For instance: <div class="panel"> <!-- Content --> </div> <div class="s ...

Angular 2.0 in conjunction with D3.js does not style SVG elements using CSS

Currently, I am utilizing Angular 2.0 TypeScript along with the d3.js library to create graphics. My main focus is on applying CSS to the axis (especially shape-rendering: crispEdges;). Do you have any suggestions? Check out the code below: var vis = d3 ...

Discovering the process of extracting a date from the Date Picker component and displaying it in a table using Material-UI in ReactJS

I am using the Date Picker component from Material-UI for React JS to display selected dates in a table. However, I am encountering an error when trying to show the date object in a table row. Can anyone provide guidance on how to achieve this? import ...