Geri çağırış Lim10Ata\Flatix\xfwidgets::gethtml yanlışdır (error_invalid_class).

Foruma xoş gəldiniz 👋, Qonaq

Forum məzmununa və bütün xidmətlərimizə daxil olmaq üçün qeydiyyatdan keçməli və ya foruma daxil olmalısınız. Foruma üzv olmaq tamamilə pulsuzdur.

Qeydiyyatdan kec

Random slider

3

GameKing

Kohnelerden
Silver istifadeci
Qoşuldu
10 Sen 2022
Mesajlar
204
Reaksiya hesabı
110
Xallar
43
Salam, Javascript proqramlasdirma dili ile random slider hazirlayiram.
Slider melumatlarini ise js array icerisinde saxlamisam.
Slider sekilleri random olaraq numayis etdire bilirem.
Lakin sistem array icerisinden random index secdiyi zaman, ele vaxt olur ki, eyni index-i minimum iki defe ard-arda eyni olaraq sece bilir.
Buna gore de slider bezen minimum 2 defe olmaq serti ile, eyni sekil ard-arda numayis olunur.
Mene bunun qarsisini almaq ucun kod lazimdir.


JavaScript:
const models = [
    {
        name: 'Bmw 418d',
        image: 'img/bmw.jpg',
    },
    {
        name : 'Mazda CX-3',
        image : 'img/mazda.jpg',
    },
    {
        name : 'Volvo S60',
        image : 'img/volvo.jpg',
    },
    {
        name : 'Skoda Superb',
        image : 'img/skoda.jpg',
    },
    {
        name : 'Honda Civic',
        image : 'img/honda.jpg',
    }
];

const countSliders = models.length;

function init(options) {

    showSlider(index);

    interval = setInterval(() => {
        if(options.random) {
                index = Math.floor(Math.random()*countSliders); //->array icerisinden random deyeri minimum 2 defe eyni olaraq secen js statement.
        }
        else {
            index = index >= countSliders ? 0 : index + 1;
        }

        //console.log(index);

        showSlider(index);
    }, options.duration);
}
 
Son redaktə:
3

GameKing

Kohnelerden
Silver istifadeci
Qoşuldu
10 Sen 2022
Mesajlar
204
Reaksiya hesabı
110
Xallar
43
Bilen kimse yoxdur deyesen?
 
3

xson

Try hard
Moderator
Qoşuldu
24 Avg 2022
Mesajlar
195
Reaksiya hesabı
50
Xallar
28
Məkan
Baku, Azerbaijan
Web sayt
qutb.az
Eləməli olduğun slideri dəyişdirməzdən əvvəl hazırki indexi alıbəgər o indexə bərabərdisə o slideri göstərmə yenidən random seçim eləsin məntiqi tutdun?
 
3

GameKing

Kohnelerden
Silver istifadeci
Qoşuldu
10 Sen 2022
Mesajlar
204
Reaksiya hesabı
110
Xallar
43
Eləməli olduğun slideri dəyişdirməzdən əvvəl hazırki indexi alıbəgər o indexə bərabərdisə o slideri göstərmə yenidən random seçim eləsin məntiqi tutdun?
mentiqini men de bilirem, sadece bele deyim de, array icerisinden ard-arda eyni itemi-i secmesini istemirem, buna gore #1 postumdaki kodda duzelis edib, burada paylasa bilersiniz?
 
Son redaktə:
3

GameKing

Kohnelerden
Silver istifadeci
Qoşuldu
10 Sen 2022
Mesajlar
204
Reaksiya hesabı
110
Xallar
43
Her zaman oldugu kimi, problemi ozum hell etdim, bilmeyenler ucun kodu asagida paylasiram.
JavaScript:
function init(options) {

    let prev;

    showSlider(index);

    interval = setInterval(() => {
        if(options.random) {
            //->do-while dongusu ile + prev deyiskeni ile problemi hell etdim.
            do {
                index = Math.floor(Math.random()*countSliders);
            } while (index == prev);
            prev = index;
        }
        else {
            index = index >= countSliders ? 0 : index + 1;
        }

        //console.log(index);

        showSlider(index);
    }, options.duration);
}
 
3

GameKing

Kohnelerden
Silver istifadeci
Qoşuldu
10 Sen 2022
Mesajlar
204
Reaksiya hesabı
110
Xallar
43
Since the topic has been resolved, I ask the admins to lock the topic.
 
Üst