lundi 19 mars 2018

How can I condense down these if statements?

I'd like to reduce the size of this if statement so it can iterate continuously until around 20, with the pattern I have below:

    if (i >= 0 && i <= 3) {
        $('.timeline__bar').css({ 
            transform: 'translateX(-0vw)',
        });
    }
    if (i > 3 && i <= 7) {
        $('.timeline__bar').css({ 
            transform: 'translateX(-92vw)',
        });
    }
    if (i > 7 && i <= 11) {
        $('.timeline__bar').css({ 
            transform: 'translateX(-184vw)',
        });
    } 
//ect ect until 20

The amount I'm transforming everytime is -92 vh units and I'm sure theres a loop pattern I can hook into too but I'm unsure how to do this.

Aucun commentaire:

Enregistrer un commentaire