Incorporate a collection of multiple images into Fancybox

Can someone help me figure out how to use fancybox to display a series of images in a lightbox? I have this JS object called fancybox_img, and here's what it contains:

{card_173: Array(1), card_171: Array(5), card_169: Array(4)}
card_169: Array(4)
0: {src: "flat6.jpeg"}
1: {src: "flat7.jpg"}
2: {src: "flat6.jpeg"}
3: {src: "flat4.jpg"}
length: 4
__proto__: Array(0)
card_171: (5) [{…}, {…}, {…}, {…}, {…}]
card_173: [{…}]
__proto__: Object

I'm trying to select each card and display the array of images like this:

jQuery('#module_properties .item-tool').click(function() {
            var idCard = jQuery(this).parents(".card").data("card");
            var imgCard = fancybox_img[idCard];
            
            jQuery.fancybox.open([
                imgCard
            ]);
            
        });

When I console log imgCard, it shows as an object with multiple image sources. Here's an example given by fancybox for displaying multiple images:

Example of opening image gallery programmatically (the opts are optional):

$.fancybox.open([
    {
        src  : '1_b.jpg',
        opts : {
            caption : 'First caption',
            thumb   : '1_s.jpg'
        }
    },
    {
        src  : '2_b.jpg',
        opts : {
            caption : 'Second caption',
            thumb   : '2_s.jpg'
        }
    }
], {
    loop : false
});

I'm not sure how to structure my data to achieve the same result as {src: 'url'},{src: 'url2'}.... Any advice would be greatly appreciated. Thanks!

Answer №1

Seems like all you need to do is replace

jQuery.fancybox.open([
  imgCard
]);

with

jQuery.fancybox.open(imgCard);

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

Toggle between multiple chart displays within a <div> using a selection list

With around 20 div sections on my webpage, I encountered an issue where selecting option 1 and then 2 still displayed the chart of 1. Any tips on adjusting the JavaScript to ensure that charts are displayed correctly when changing selections in the list? W ...

Unable to reach the child object in JavaScript, yet it remains within view

Encountering an issue with a JavaScript object retrieved from a MongoDB: when logging the parent object, the child object is visible. However, attempting to access or log the child object results in undefined. const templateResponse = await this.dbService. ...

Problem Encountered with Jquery Validation for Name Field (Restriction to Alphabetic

I am struggling to validate a name format using a predefined jQuery validation tool. My intention is for the name field to accept only characters, but even with the correct regex pattern, it still allows numbers to be entered. The specific script I am us ...

Converting a comma-separated string into an array of integers using jQuery

Is there a way in jQuery to convert a string containing multiple numbers into an array? The string in question is as follows: let values = "901,235,342,421,345,745,544,324,445,123,232,986,345,678"; ...

Is there an npm module available that can automate a daily task at a specified time in a Node.js environment?

Searching for an NPM Module to integrate into a Node.js application that can send notifications via email and SMS daily at 9am local time. Any suggestions or solutions would be greatly appreciated! ...

Error: Major browser version not recognized

I am currently facing an issue while trying to integrate Bootstrap 4 with my Angular setup. I have executed the command npm install --save bootstrap@next, however, I encountered a runtime error: ./node_modules/css-loader?{"sourceMap":false,"importLoaders" ...

Exploring the (*ngFor) Directive to Iterate Through an [object Object]

Attempting to iterate through the array using *ngFor as shown below. let geographicalArea = [{ "_id": "5e77f43e48348935b4571fa7", "name": "Latin America", "employee": { "_id": "5e77c50c4476e734d8b30dc6", "name": "Thomas", ...

Tips for processing bound data in AngularJS

Is it possible to manipulate data that is bound with AngularJS after the fact? I am creating a basic search page and have generated the results using this code: ... <div class="row" ng-repeat="document in sc.searchResult.content"> <blockquot ...

What would be the best TypeScript target and libs to utilize in a transpiler-free Node.js project?

If I am running a TypeScript Node.js project with the command tsc && node build/index.js (where tsc builds into build/ and index.ts is in the project), what values should be used in lib and target in tsconfig.json to ensure access to the latest TypeScrip ...

Adding fresh elements to the state array in React Native

I am experiencing an issue with the code provided below: import React, { Component } from "react"; import { SafeAreaView } from 'react-navigation' import {Keyboard, Text, View, TextInput, TouchableWithoutFeedback, Alert, KeyboardAvoidingView, St ...

Securing user access in react-native with redux and asyncStorage

As a newcomer to React Native and React Redux, I am currently working on a project that involves implementing authentication and authorization. The goal is to display a splash screen for a few milliseconds, then redirect the user to either the login page ...

Confusion with Javascript callbacks - seeking clarity

I am having difficulty grasping the concept of callback functions. I know that they are functions passed as parameters to other functions. My assumption was that when a function is passed as a parameter, it would be recognized as a callback function and ex ...

Implementing a feature to close the drawer component from the main page by clicking on the menu button in React-js

Just starting out with reactjs and I've got my main page set up like this: <div > <AppBar position="flex" style={{backgroundColor:'#1A437E'}}> <Toolbar> <IconButton edge="end" color= ...

What methods are available to test my website across different browsers such as outdated versions of Internet Explorer like IE8?

Currently, I am working on Chrome with Windows 7 OS installed. However, Windows 7 does not support Internet Explorer 8. This is causing issues when trying to view my web pages in the IE8 version and older. How can I resolve this problem? I have attempted ...

Tips for personalizing a column graphic in HTML

Currently, I am utilizing chart.js but struggling to create a chart like the one shown below https://i.sstatic.net/axSFP.jpg where the bar aligns with the dotted line. I attempted this approach in JSFIDDLE Kindly recommend some resources that can help ...

What could be causing Jquery's $.ajax to trigger all status codes even when the call is successful?

Here is a simple Jquery ajax function call I have. function fetchData(){ var jqxhr = $.ajax({ url: "../assets/js/data/users.json", type: "GET", cache: true, dataType: "json", statusC ...

Determining the position of a jQuery element within an array

I have multiple images loaded into the DOM using jQuery. All images are set to 'display: none' except for one that is set to 'display: block'. I am trying to determine the index of this particular image once selecting the img array from ...

Tips for efficiently waiting for the outcome in a unified function for multiple callbacks within node.js

Perhaps the question title is not the most appropriate, but let me explain what I am trying to achieve in my code // First Callback Function connection_db.query(get_measure_query,function(err,user_data1){ if(err){ // throw err; ...

Is SPE.Group.tick experiencing issues with a faulty delta argument in Three.js / ShaderParticleEngine?

I recently started using the ShaderParticleEngine library in Three.js to set up particle emitters. After browsing through various code snippets online, I managed to get an emitter up and running. Initially, I thought it wasn't working as I could only ...

ways to invoke javascript function on body loading

I'm struggling to invoke a JavaScript function when the body loads. Currently, I have the function call on a button but cannot get it to work when added to the body load event. HTML: <body onload="bodyload();"> JavaScript: function bodyload( ...