Load the flexslider once the fancybox container is opened

In my experience, I have found flexslider and fancybox to be very useful plugins. Individually, they work perfectly fine on a website that I am currently working on. However, when I tried placing a flexslider gallery inside a fancybox div, I encountered a problem. It's important to mention that this is a responsive website, meaning that all the widths are based on percentages rather than fixed values.

Initially, everything seemed to be functioning correctly. I loaded fancybox and flexslider displayed properly with its width set at 50% of the fancybox container. But when I added display: none; to the fancybox div in order to hide it until needed, an issue arose. When fancybox loaded, all the images within flexslider appeared tiny, even though the width of the flexslider div was correct. My assumption is that because flexslider loads along with the page, it has no knowledge of its own width. This explains why the issue does not occur when display: none; is set.

This is the current Javascript code I'm using to load both plugins:

// =FANCYBOX

$(".fancybox").fancybox({
    padding : 2,
    nextEffect: 'fade',
    prevEffect: 'fade',
    title: false,
});

// =FLEXSLIDER 

$(function(){

    if($(".flexslider").length > 0) {
        $(".flexslider").addClass("loading");
        // Can also be used with $(document).ready()
        $(window).load(function() {
            $('.flexslider').flexslider({
                animation: "slide",
                directionNav: false,
                slideshowSpeed: 5000,
                animationSpeed: 360,
                easing: "easeInQuad",
                useCSS: false,
                start: function(slider){
                    $('.flexslider').removeClass('loading');
                }
            });
        });
    }
});

I am wondering if there is a way to force flexslider to initialize again after fancybox becomes visible?

Appreciate any help or insight,

Steve

Answer №1

To achieve the desired outcome, you can try incorporating the initialization of flexslider within fancybox's afterShow callback function using the following code:

jQuery(document).ready(function($){
    $(".fancybox").fancybox({
        padding : 2,
        nextEffect: 'fade',
        prevEffect: 'fade',
        title: false,
        afterShow: function(){
            $('.flexslider').flexslider({
                // flexlslider options
            });
        }
    }); // fancybox
}); // ready

Answer №2

If you want to make sure that flexslider can properly determine image size, it is advisable to avoid using the display:none; property for fancybox.

Here's a helpful technique:

  1. Place the fancybox div inside a parent div.

  2. Apply the visibility:hidden; property to the fancybox div.

  3. Set the parent div to display:none;.

I hope this tip proves useful to you!

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

Guide to placing an image in a designated position

I am looking to achieve the following scenario: Whenever a user uploads an image, it should appear in one of the smaller boxes on the right. Subsequent image uploads by clicking on the big box should populate the other small boxes on the right. Please refe ...

Utilize Python to extract a table from an HTML document

I would like to retrieve a table from an HTML file. Below is the code-snippet I have written in order to extract the first table: import urllib2 import os import time import traceback from bs4 import BeautifulSoup #find('table',{'class&ap ...

Deleting content from cells in table for all even td items

This problem has been causing me frustration; I've attempted various methods using jquery and CSS, but to no avail. Essentially, I have the following table structure: <table id="mainTable"> <thead> <tr> <th>Arrival ...

What advantages can be gained from having multiple package.json files within a single application?

Embarking on the journey of creating my inaugural full react web application entirely from scratch. Previously, I've mainly worked on assignments that were partially pre-made for me. While setting up my project, I couldn't help but notice that I ...

New HTML output is displaying strangely when using jQuery AJAX

My jQuery AJAX function retrieves new HTML content from a PHP script. The PHP script is functioning correctly and sending back the accurate HTML to jQuery. However, when I utilize the html() function, the displayed HTML is incorrect. To verify the returned ...

What could be causing the issue with the 100% height and 100% width not functioning properly on my ASPX page?

The CSS and HTML code work perfectly in an isolated test environment: body, html { height: 100%; min-height:600px; min-width:800px; overflow:hidden; margin:0;padding:0; } html {overflow:auto;} .fill {height:100%; width:100%; backgro ...

Tracing a path with a snapping motion using my thumb

Before we begin, let's take a look at the example below. The functionality of this component should mimic that of an input type range. However, I am facing some challenges in calculating the step value and snapping the thumb onto the trail based on t ...

Calendar: Display upcoming dates within the next week starting from the current week

Hey there! I have a calendar that includes next and previous buttons. When the user clicks on the next button, the schedule for the upcoming week will be displayed. However, if the user clicks again, nothing happens. My goal is to only show dates for the n ...

Generate a new cookie only when it is not currently present

My objective is to: Determine if a cookie named "query" exists If it does, take no action If not, create a cookie called "query" with a value of 1 Please note: I am working with jQuery version 1.4.2 and utilizing the jQuery cookie plugin. Any recommend ...

Creating session variables in Joomla using checkboxes and AJAX

I'm currently working on implementing session variables in Joomla with AJAX when checkboxes are selected. Below is the code snippet from select_thumb.ajax.php file: $_SESSION['ss'] = $value; $response = $_SESSION['ss']; echo ...

React-Redux is throwing a TypeError due to its incapability of reading the property 'map' which is undefined

I'm still fairly new to diving into React and Redux, and I find myself a bit puzzled. My main objective is to populate HTML with a plethora of JSON data through GET requests. Utilizing react and redux to control the state of these objects, however, i ...

Having trouble utilizing a function with an async onload method within a service in Angular - why does the same function work flawlessly in a component?

I successfully created a component in Angular that can import an Excel file, convert it into an array, and display its content as a table on the page. The current implementation within the component looks like this: data-import.compoent.ts import { Compo ...

Creating an SQL select statement with a three-level expression is a complex task that requires careful planning and

How can I create a SQL select query with 3 levels of expressions and statements? Typically, my website operates on an SQLite database and the search results are displayed using the following SQL query: "SELECT DISTINCT * FROM amz WHERE Title LIKE \" ...

What issues can arise in JavaScript if the URL length is not zero when there is no match found?

Upon clicking the "Open Windows" button in Code A, I expected the two links to open in two tabs simultaneously in Chrome, which is exactly what happened. However, when I added a blank line in the textarea control in Code B, only the link http:// ...

Tips for transferring client-side data to the server-side in Angular, Node.js, and Express

Seeking a straightforward solution to a seemingly basic question. I am utilizing Angular's $http method with a GET request for a promise from a specific URL (URL_OF_INTEREST). My server runs an express script server.js capable of handling GET reques ...

Utilizing HTML5 to automatically refresh the page upon a change in geolocation

I have a web application built with AngularJS. One of the functionalities is activated only when the user is in close proximity to specific locations. To make this work, I can constantly refresh the page every 5 seconds and carry out calculations to dete ...

The Typescript Select is displaying an incorrect value

Here's the code snippet I've been working with: <select #C (change)="changeSelect(zone.id, C.value)"> <option *ngFor="let town of townsLocal" [attr.value]="town.data" [attr.selected]="town.data === zone.town && 'selected& ...

Using AJAX to send a POST request with the PHP $_FILES superglobal while preventing the default form submission with the onclick

Seeking to implement a photo upload form using an AJAX script that is currently in place. Currently, I have the html form with a file input field. Upon submission, there is an onclick event triggering "PostForm(); return false;" This action directs to a ...

Issue with scroll down button functionality not functioning as expected

Is there a way to create a simple scroll down button that smoothly takes you to a specific section on the page? I've tried numerous buttons, jQuery, and JavaScript methods, but for some reason, it's not working as expected. The link is set up co ...

floating point for a list item compared to other elements

nav > ul > li { float: left; } #one { float: left; } <nav> <ul> <li> he has a cow </li> <li > he has a dog </li> <li> he has a mouse </li> </ul> & ...