我正在尝试将以下内容从SCSS重写为Stylus:
link to original SCSS codepen grid loop
// Total columns for layout
$total-columns: 6;
$col-widths: ();
@for $i from 1 through $total-columns {
@for $j from 1 through $i {
$w: ($j/$i);
// If the width doesn't already exist
@if not index($col-widths, $w) {
.col-#{$j}-#{$i} {
width: $w * 100%;
}
// Add the width to the array
$col-widths: append($col-widths, $w, comma);
}
}
}
但我坚持的部分是
@if not index($col-widths, $w)
如果类w已经存在,我不知道如何检查col-widths数组,从而不再添加它。
这是我到目前为止所得到的,但它不起作用。我错过了什么?
total-columns = 6
col-widths = ()
for i in 1..total-columns
for j in 1..i
w = (j/i)
if index in col-widths is not w
.width{j}of{i}
lost-column: w
else
push(col-widths, w)
答案 0 :(得分:0)
您可以在此处使用in
运算符(实际上,您的代码几乎是正确的)。
total-columns = 6
col-widths = ()
for i in 1..total-columns
for j in 1..i
w = (j/i)
unless w in col-widths
.width{j}of{i}
lost-column: w
push(col-widths, w)