7

I'm trying to figure out who to apply a cascading style effect by delaying animation a few seconds for each iteration:

.stashCard {
    background-color:white;
}

.in(@delay) {
    -webkit-animation: swing-in-left-bck .6s cubic-bezier(.175, .885, .32, 1.275) @delay both;
    animation: swing-in-left-bck .6s cubic-bezier(.175, .885, .32, 1.275) @delay both
}

.out(@delay) {
    -webkit-animation: fade-out .2s ease-out @delay both;
    animation: fade-out .2s ease-out @delay both
}

.baseKid {
    width: 50px;
    height: 50px;
    display: inline-block;
}


.selected
{
    .kid();
    color:yellow;
}

.kid {
    .out(0s);
    .baseKid();
}
.stashCard:hover .kid {
    .in(0s);
    .baseKid();
}

.stashCard:hover .kid.selected {
    .in(0s);
    .baseKid();
}
.stashCard:hover .kid2.selected {
    .in(0.05s);
    .baseKid();
}

.stashCard:hover .kid2 {
    .in(0.05s);
    .baseKid();
}

.stashCard:hover .kid3.selected {
    .in(0.1s);
    .baseKid();
}

.stashCard:hover .kid3 {
    .in(0.1s);
    .baseKid();
}

.hover {
    -webkit-animation: text-shadow-drop-center .6s both;
    animation: text-shadow-drop-center .6s both
}
.unhover {
    -webkit-animation: untext-shadow-drop-center .6s both;
    animation: untext-shadow-drop-center .6s both
}

And this is how I'm applying it:

export const PopupMenu = (props: InputProps) => {
    return <div className="menu" style={props.style}>
        <VoteOption count="actors" className={props.selectedCounts.indexOf("actors") >= 0 ? "selected kid" : "kid"}  onClick={props.onClick} icon="sentiment_very_satisfied" tip="Real actors" />
        <VoteOption count="audio" className={props.selectedCounts.indexOf("audio") >= 0 ? "selected kid2" : "kid2"} onClick={props.onClick} icon="music_video" tip="Great audio quality" />
        <VoteOption count="picture" className={props.selectedCounts.indexOf("picture") >= 0 ? "selected kid3" : "kid3"} onClick={props.onClick} icon="photo_camera" tip="Great picture quality" />
    </div>;
}

Obviously this is inefficient and requires a lot of copy + paste, is there a way I can make it such that I can add as many voteoptions as I like and less can write out css which will iterate over all child components and apply with the correct offset start time?

1 Answer 1

6
+50

You can use a loop to achieve it:

.in(@delay) {
    -webkit-animation: swing-in-left-bck .6s cubic-bezier(.175, .885, .32, 1.275) @delay both;
    animation: swing-in-left-bck .6s cubic-bezier(.175, .885, .32, 1.275) @delay both
}

.out(@delay) {
    -webkit-animation: fade-out .2s ease-out @delay both;
    animation: fade-out .2s ease-out @delay both
}

.baseKid {
    width: 50px;
    height: 50px;
    display: inline-block;
}


.loop(@counter) when (@counter > 0) {
  .loop((@counter - 1));    // next iteration
  .kid@{counter} {
    .in(0.05s * (@counter - 1));
    .baseKid();
  }
  .kid@{counter}.seleted {
    width: (10px * @counter); // code for each iteration  
  }
}

.stashCard:hover {
  .loop(5); // launch the loop  
}
Sign up to request clarification or add additional context in comments.

Comments

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.