The resizing of the lightbox image is not functioning properly

Something strange is happening with my website. Whenever I resize the window and try to open the lightbox, the image appears in the wrong size. It's only when I resize the window again that the lightbox detects the correct window size and properly displays the image.

<script type="text/javascript">
    jQuery(document).ready(function($){
        $(".fancybox").fancybox({
            type:'inline',
            autoCenter : true,
        afterShow: function(){
            $('.flexslider').flexslider({
                animation: "slide",
                controlNav: "thumbnails",
                slideshow: true,
                touch: true,
                animationLoop: false
            });
        }
    }); // fancybox
    }); // ready
</script>

The demo of the site can be found here link to demo on site. You can also download a small zip file containing the contents from this link zip 26kb.

To replicate the error I am experiencing:

A. Start by opening the demo.

B. Click on "Inline" and then close it.

C. Resize the browser window to around ~400px and click on "Inline" again.

D. The image should appear in the wrong size. Once you resize the window with the lightbox open, the issue is fixed. However, I want the image to always display in the correct size when launching the lightbox initially.

The image is consistently cropped incorrectly. Sometimes two images show up, and other times the image extends beyond the screen.

https://i.sstatic.net/N280A.png https://i.sstatic.net/B7ue2.png

Answer №1

To trigger a window resize in your JavaScript code after initializing flexslider, you can simply include the following snippet:

$(".fancybox").fancybox({
     type: 'inline',
     autoCenter: true,
     afterShow: function() {
          $('.flexslider').flexslider({
            animation: "slide",
            controlNav: "thumbnails",
            slideshow: true,
            touch: true,
            animationLoop: false
          });

          // Force browser to re-calculate dimensions
          $(window).resize();
     }
 });

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

Error with Husky during precommit:

I've upgraded to the latest version of yarn and now I'm setting up Husky in my project. Here is the content from .huskyrc.json: { "hooks": { "pre-commit": "lint-staged", "pre-push": "npm run ...

Manipulating and Parsing HTML files locally using Node.js

Hey there! I have a bit of an odd question that might be on the basic side. I'm diving into web development and front-end work, so I'm still fairly new to it all. The Scenario To give you some background, my experience with JS is mainly from usi ...

Modifying the dimensions of media:thumbnail in Blogger's RSS Feed

I came across this post, but it seems like there have been updates in the past 4 years regarding how thumbnails are generated for Blogger posts. I've attempted various methods, but so far none of them have been successful. If anyone could assist me in ...

The argument in question has not been defined

Experimenting with AngularJS, I encountered an error message in the browser console when trying to display a particular example: Error: Argument 'mainController as mainCtrl' is not a function, got undefined at Error (native) at bb My pr ...

The CSS property for setting the background color on the body element is not functioning properly

I am attempting to make changes to my app.scss file in my Symfony 4 project. Unfortunately, the background-color property is not being applied as expected. body { background-color: #ccccff; } In my base.html.twig file, I have the following structure: ...

What are the best ways to ensure my website looks great on both desktops and phones? I'm considering using media queries,

My website needs to be made responsive for both desktop and mobile devices. With around 200 lines of CSS code, I'm wondering how best to achieve this without having to add another 200 lines for media queries. Any simple solutions or advice on the most ...

Angular 5 - Strategies for excluding specific properties from Observable updates

Currently, I am in the process of developing a webpage where users can view and like various videos. The video content and user likes are stored in a database, and I have implemented two Angular services for handling data retrieval and storage. However, I ...

How can you ensure that text inside a tag is styled as italic using font-style: italic and the !important keyword in HTML and CSS?

I've created an HTML site using chordpro.php generator, and the specific aspect related to this query is as follows: <div class="song"> <table border=0 cellpadding=0 cellspacing=0 class="songline"> <tr class="songlyricchord"><td& ...

Is there anyone available to assist me with troubleshooting a login session that is not functioning properly

I'm a beginner in php and I'm facing an issue with logging in as a different user in a project. After logging out and returning to the browser, the previous user's window keeps opening. Below is the code for index.php: <?php if ( ...

Is it possible to streamline this HTML using jQuery to generate it?

I've been working on creating little speech bubbles for an upcoming website. While the code to make these divs is functional, I find it repetitive and time-consuming to write out every time I want to add a bubble. My solution is to utilize jQuery and ...

Magic chest - triggered upon touch, disengaged upon tap elsewhere

Is there a way to create a div box that triggers a specific event when clicked, but only affects the time when we click somewhere else afterwards? It should be designed so that clicking multiple times in the box does not produce any additional effects. ...

I'm having trouble making out the object items below until I focus more closely

I seem to be having trouble reading the object items below, especially until I reach the 'subscription' section. It seems to be functioning properly but I still need to understand its contents 'subscription [current_period_end]': &apos ...

Ensure that the extension is only loaded once Angular has fully loaded

I am currently working on a Chrome extension that incorporates event listeners to elements within a page utilizing Angular 1.2.10. The following code snippet is an example of what I have: window.addEventListener("load", (event) => { var switchButton = ...

Issue with displaying error message on span element during validation

Is there a way you can recommend for displaying the error message within element with id #genderError instead of after it? errorPlacement: function(error, element) { if (element.attr("name") == "myoptions" ) error.appendTo('#genderError'); ...

The correct method to remove a specific attribute from the primary state in Redux that employs combineReducers - React Redux

I have been working on an app that requires authorization features such as registration, login, and logout. To achieve this, I am using redux. While the registration and login functionalities are operational, I encountered issues when attempting to delete ...

What is causing the malfunction in this JSON data?

I need assistance with using the MySQL remote data as tags with the select2 plugin. Unfortunately, my understanding of JSON is limited, and I require help in rectifying the JSON format. $("#e7").select2({ placeholder: "Search for a movie", minimum ...

Create a function that replaces items with alphabets

My goal is to create a straightforward hangman game. When a category is chosen and the "New Word" button is clicked, a random word from the selected list will be displayed as underscores. As letters are guessed and matched with those in the word, they will ...

Managing posts and comments in ASP.NET: A guide to effective control

I am working on developing a webpage using asp.net where users can view and comment on posts, similar to social media platforms like Facebook or Twitter. However, I have been struggling to find the right control to display posts from a database and enable ...

The asp:Button with a fixed/absolute position is unresponsive in both Firefox and Google Chrome, making it un

I am currently coding in ASP.NET. I have a button that is clickable on Internet Explorer but not on Firefox or Google Chrome. After investigating, I found out that the issue lies in its CSS property being set to position: absoulute OR position:fixed. Her ...

Deciphering the sequence of operations in a CSS style sheet

Review the CSS stylesheet below: #start_experiment_button { display: inline-block; color: black; border: 3px outset gray; background-color: #CCCCCC; padding: 8px; text-decoration: none; font-family: Arial, Helvetica; font-weight: bol ...