Fancybox how to open dynamically with a variable

169 Views Asked by At

so right now I'm trying to load a fancybox modal with a javascript string I got back from an Ajax call. What ends up happening is the modal opens up with this code inside rather than converting them to the appropriate images/thumbnails.

[{ src : 'e2121a1caf564e92be14cfb38d094901/9234b96c09_640.jpg', opts : { thumb: 'e2121a1caf564e92be14cfb38d094901/9234b96c09_640.jpg' } }]
1

There are 1 best solutions below

2
Janis On

It is not clear what version are you using, here is an example for v3:

$.fancybox.open([
  {
    src   : 'https://source.unsplash.com/i-FqQIkJMqg/1536x2304',
    thumb : 'https://source.unsplash.com/i-FqQIkJMqg/200x200'
  }, 
  {
    src   : 'https://source.unsplash.com/z55CR_d0ayg/1279x853',
    thumb : 'https://source.unsplash.com/z55CR_d0ayg/200x200'
  }
]);