Skip to content

Instantly share code, notes, and snippets.

@mizhon
Last active February 1, 2019 16:00
Show Gist options
  • Save mizhon/525e3d333d3b2c527c56e42944f0108c to your computer and use it in GitHub Desktop.
Save mizhon/525e3d333d3b2c527c56e42944f0108c to your computer and use it in GitHub Desktop.
Less loop expression
/* Define two variables as the loop limits */
@from: 1;
@to: 12;
/* Create a Parametric mixin and add a guard operation */
.loop(@index) when(@index =< @to) {
&:nth-child(@{index}) {
animation-delay: (@index - 1) /12s; // calc with the unit
transform: rotate(30deg * (@index - 6)) translateY(-150%);
}
.loop(@index + 1);
}
/* the mixin is called, css outputted and iterations called */
.loop(@from);
/* out put css style */
/* convert online: https://www.webtoolkitonline.com/less-to-css.html */
:nth-child(1) {
animation-delay: 0s;
transform: rotate(-150deg) translateY(-150%);
}
:nth-child(2) {
animation-delay: 0.08333333333333333s;
transform: rotate(-120deg) translateY(-150%);
}
:nth-child(3) {
animation-delay: 0.16666666666666666s;
transform: rotate(-90deg) translateY(-150%);
}
:nth-child(4) {
animation-delay: 0.25s;
transform: rotate(-60deg) translateY(-150%);
}
:nth-child(5) {
animation-delay: 0.3333333333333333s;
transform: rotate(-30deg) translateY(-150%);
}
:nth-child(6) {
animation-delay: 0.4166666666666667s;
transform: rotate(0deg) translateY(-150%);
}
:nth-child(7) {
animation-delay: 0.5s;
transform: rotate(30deg) translateY(-150%);
}
:nth-child(8) {
animation-delay: 0.5833333333333334s;
transform: rotate(60deg) translateY(-150%);
}
:nth-child(9) {
animation-delay: 0.6666666666666666s;
transform: rotate(90deg) translateY(-150%);
}
:nth-child(10) {
animation-delay: 0.75s;
transform: rotate(120deg) translateY(-150%);
}
:nth-child(11) {
animation-delay: 0.8333333333333334s;
transform: rotate(150deg) translateY(-150%);
}
:nth-child(12) {
animation-delay: 0.9166666666666666s;
transform: rotate(180deg) translateY(-150%);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment