1

Simply put I'm using a plugin called magnific popup, which is a lightbox popup, and you can initialise it from a set of options on dom ready:

$.magnificPopup.open({
    items: [
        { src: "img-src.jpg"  },
        { src: "img-src2.jpg" },
        { src: "img-src3.jpg" },
        etc
    ]
});

I've created an array of images in javascript held within a div which then need to be passed into that list. Only I'm not sure how. Heres what I've got.

var $zoomurl = $('.gallery').find('img').attr('src');

How do I get the contents of var $zoomurl into items options? An explanation of the answer would be of value also!

1 Answer 1

1

Try using $.map()

$.magnificPopup.open({
    items: $.map($(".gallery").find("img"), function(el) {
             return {"src":el.src}
           })

});
Sign up to request clarification or add additional context in comments.

15 Comments

Thats worked! Thanks for your help. I have a slight problem with click event tho, it opens the gallery at the first image all the time. Theres an index selector that is accepted by magnific popup. Is there anyway of counting the items, 0 being the first entry, and using that to select the correct image?
$.magnficPopup.open({ #items }, #index );
@Aaron Not tried $.magnificPopup , though should be able to select item within items using $.magnficPopup.open(items, 0)
Yup, just not sure how to count the items with the above code and provide that index number. $.magnificPopup.open({ items: $.map($(".gallery").find("img"), function(el) { return {"src":el.src} }) }, #count );
Done it! Don't need to retrieve the index, because flickity already has a cellIndex function which we can use to tell magnific what image to open! Its all working... thanks for your help @guest271314 :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.