E
E
Egor Mikheev2015-10-21 23:12:07
JavaScript
Egor Mikheev, 2015-10-21 23:12:07

How to replace an array with a value and reinitialize a function?

Hello, it's hard with the theory, so I can't figure out what to do in this case:

Is there a function (or method?) - .vegas();
It contains an array of elements. interested in - slides:
In general, when you click on some buttons, change the array of photos and reinitialize the function to immediately work.
To be honest, I don't know which way to go.

$("#example, body").vegas({
    slides: [
        {src: "./img/bg/4.jpg"},
        {src: "./img/bg/5.jpg"},
        {src: "./img/bg/6.jpg"},
        {src: "./img/bg/7.jpg"},
        {src: "./img/bg/8.jpg"},
        {src: "./img/bg/9.jpg"}
    ],
    overlay: true,
    transition: [ 'fade', 'fade2' ],
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wol_fi, 2015-10-22
@wol_fi

I guess based on the sources ( https://github.com/jaysalvat/vegas/blob/master/src... something like this:

//убиваем текущий инстанс
$("#example, body").vegas('destroy');
//вызываем новый, уже с другими фотками
$("#example, body").vegas({
    slides: [
        {src: "./img/bg/4.jpg"},
        {src: "./img/bg/5.jpg"},
        {src: "./img/bg/6.jpg"},
        {src: "./img/bg/7.jpg"},
        {src: "./img/bg/8.jpg"},
        {src: "./img/bg/9.jpg"}
    ],
    overlay: true,
    transition: [ 'fade', 'fade2' ],
});

You can also try without recreating the instance:
var slides = [
        {src: "./img/bg/4.jpg"},
        {src: "./img/bg/5.jpg"},
        {src: "./img/bg/6.jpg"},
        {src: "./img/bg/7.jpg"},
        {src: "./img/bg/8.jpg"},
        {src: "./img/bg/9.jpg"}
    ];
$("#example, body").vegas('options', 'slides', slides)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question