jQuery gallery remains hidden until the overlay is manually revealed

I'm experiencing an issue with a jQuery gallery placed within a full-screen absolutely positioned element that is initially hidden with display: none. When I click a button to reveal the element using jQuery .show(), only the full-screen overlay appears, not the gallery inside it. However, if I remove the initial display property, or resize the browser window, the gallery becomes visible. Here's a link to a demo showcasing the problem: http://codepen.io/riogrande/pen/WxxjvJ

Here's the HTML code snippet:

<div class="gallery">
    <div class="demo">
        <ul id="lightSlider">
            <li data-thumb="static/images/galerija/thumbs/15.jpg">
                <img src="static/images/galerija/15.jpg" alt="galerija"/>
            </li>
            ...
        </ul>
    </div>
    <div class="close-gallery">
        <img src="static/images/close.png" alt="close"> Close Gallery
    </div>
</div>

The CSS styling for the gallery is as follows:

.gallery {
  position: absolute;
  width: 100%;
  height: 100%;
  background: #2a2d2c;
  z-index: 99999;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  display: none;
}
...

And here's the JavaScript/jQuery code used for the LightSlider gallery:

$(document).ready(function () {
        $('#lightSlider').lightSlider({
            gallery: true,
            item: 1,
            loop: true,
            slideMargin: 0,
            thumbItem: 9
        });
    });

    $('.open-gallery-button').click(function () {
        $('.gallery').show();
        $('body').scrollTop(0);
    });

    $('.close-gallery').click(function () {
        $('.gallery').hide();
        var slider = $('#lightslider').lightSlider();
    });

Despite clicking the open gallery button, only the overlay is displayed, as shown in the following image:

https://i.sstatic.net/3sRbH.png

However, upon resizing the browser window, the gallery content becomes visible:

https://i.sstatic.net/2Qple.png

If I remove the display property from the CSS altogether, the gallery functions as expected:

https://i.sstatic.net/2yYfz.png

For more details and to see the issue in action, check out the demo link: http://codepen.io/riogrande/pen/WxxjvJ

Answer №1

Instead of multiple overlays, you can use just one <div> and update its background, z-index, and content on click using toggleClass, for instance.

I have made some modifications to your code to provide a functional example, which you can access here: http://codepen.io/anon/pen/vKKJEq

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

An error has been caught in the Angular JS application while using the highcharts-ng module: [$injector:modulerr]

I'm encountering an issue while trying to integrate Highcharts into my Angular/Node/Express application. I am utilizing the highcharts-ng directive available at https://github.com/pablojim/highcharts-ng Every time I run my app, I consistently receive ...

Rearranging the layout of elements: CSS switches up the text and button,

Having an issue. I created a background image with gradient colors for my web project and clipped it. Within this element, there is text and a button that I want to be centered inside the element - with the text above and the button below. Initially, ever ...

The TypeScript compiler is unable to locate the name 'window'

Within my Meteor/React project, I encounter the following line of code: let gameId = window.prompt("Please input the ID of the game you would like to load."); The TypeScript compiler presents an error during transpiling: Cannot find name 'window&apo ...

What is the best way to ensure that a component remains the highest layer on a react-leaflet map?

I am encountering an issue where the table on my page only shows for a brief second when I refresh the page, and then it disappears. The Map Component being used is a react-leaflet map. I would like to have a component always displayed on top of the map wi ...

Verify form input data using jquery prior to submission

When I submit a form, I use JavaScript to check the length of the Title field and the number of attached files. If either condition is not met, I prevent submission and display an error notification. Here's an example snippet of my code. $(document ...

Styling select input forms with Bootstrap 3

I'm looking to create a select dropdown menu that matches the style of other inputs in a bootstrap 3 form. You can view an example of what I want to achieve on this plunker or see the image below: This CSS code is included in the header: <!-- Boo ...

watching a video on my site

I've been struggling to embed an .mp4 video file into my webpage. Despite searching on websites like this one and w3c here, I haven't found a solution yet. It seems that I need to use two file formats (mp4 and ogv) and I'm unsure if I can us ...

Is it possible to turn off Angular CLI ng build linting for a specific directory?

I am facing an issue with a specific directory in my project template that I want to exclude from linting. Despite excluding it in both tsconfig and eslint, running eslint works fine but when using ng build, the directory is still included in linting and e ...

The setState method fails to properly update the state

I am currently utilizing React JS. Below is the code for my React class: class MyReactComponent extends React.Component{ constructor(props){ super(props); this.state = { passAccount: { email: "Email&quo ...

Adding an information panel to each column in jqgrid allows the grid to display a scrolling feature

We have implemented a jQuery grid where the last column contains a link. When this link is clicked, a new panel should appear providing additional information. To achieve this, we utilized a formatter that generates a hidden div along with the link. Howev ...

What is the best method for converting a string picture URL into an image and showcasing it in an image tag?

I have a URL for an image that looks like this: C:\inetpub\MaujApp\OMSAPI\ManualReceivingImages\WhatsApp Image 2021-03-24 at 12.07.41 PM.jpeg My goal is to convert the original image and display it to the user using jQuery. I woul ...

Inform the PHP backend that the browser has been closed by the frontend Angular application

Currently, I am working on an Angular project that is interacting with a backend project created using PHP and ZF3. I am trying to figure out the most efficient method of informing the backend project when the user closes the browser window. Initially, I ...

Tips for extracting the most deeply nested object in a JSON file using JavaScript

Is it possible to access the innermost object without knowing the path names? Consider this JSON example: const data = { first: { second: { third: {innerObject} } } ...

Strategies for accessing the initial portion of an AJAX response

When using ajax to call an URL with dataType HTML, the response includes two parts such as accesstoken=1&expires=452. In this scenario, only the access token is needed. Using alert(response) displays both parts. How can the access token be extracted? ...

Unable to successfully perform DELETE or UPDATE operations with Axios MySQL, encountering errors

I am currently working on a project that involves using Axios with Node.Js to perform a delete request in a MySQL table. However, I seem to be encountering an issue as I am not receiving any errors in the console despite having an error catch console.log s ...

Determining the file path relative to the project/src directory in Node.js

Currently, in my node.js project I am utilizing log4js and aiming to include the file name where the log record was added. However, when using __filename, it provides me with the absolute path. var logger = log4js.getLogger(__filename) This results in lo ...

What is the best way to prevent my images from resizing in a Bootstrap 4 carousel?

I am working on a website where users can upload images of various sizes. These images are then displayed in a Bootstrap 4 carousel. I want to ensure that the carousel maintains a consistent dimension across different screen sizes without changing the widt ...

Obtain the IP address of a Node application running within a Docker container

I currently have a node express application set up in a Docker container, and I am attempting to record the IP address of each incoming request within the app. However, due to running behind a firewall, my current method "req.headers['x-forwarded-for& ...

Bringing a React Context Back to its Original State

The default state of a React Context is defined as: export const defaultState: UsersState = { isModalOpen: false, isCancelRequest: false, companyId: 0, users: [] }; After cancelling the modal, the goal is to reset the state back to its default va ...

Is it possible to refresh the JSViews data that is underneath using an onclick event?

I have created a photo gallery using a JSViews template which includes upvote and downvote buttons. When these buttons are clicked, it triggers a database update to increase the score. However, I am facing an issue with updating the Score field in the HTML ...