首先,让我警告你,我的数学知识相当有限(因此我来这里询问这一点)。
这是一个愚蠢的例子,但我本质上想要的是有一个可变的行数,并且能够设置一个最大值,然后对于每个连续的行,将该值减小到一半,然后开始将该值再次增加到最后一行的最大值。
为了说明这一点。给定:maxValue = 20和rows = 5,我需要能够获得行值的下列值(是的,甚至是0):
row 1: 20
row 2: 10
row 3: 0
row 4: 10
row 5: 20但是有一些限制,因为我试图在使用SASS的Compass中做到这一点。有关可用的操作,请参阅here,但为了让您了解它的要点,只有基本的操作可用。
我可以遍历各行,因此只需要对序列中的每一行执行计算即可。这是我可以使用的循环类型:
$maxValue:20;
$rows:5;
@for $i from 1 through $rows {
// calculation here.
}发布于 2012-11-28 22:24:11
我以前并没有真正使用过SASS,但是使用基本的if和floor函数尝试一下,不确定是否可以工作
// set various variables
$maxValue:20;
$rows:5;
// get row number before middle row, this instance it will be 2
$middleRow = floor( $maxValue / $rows )
// get increment amount, this instance should be 10
$decreaseValue = ( max / floor( rows / 2) )
@for $i from 0 through $rows - 1 {
@if $i <= $middleRow {
( $maxValue- ( $decreaseValue * $i ) )
}
@else{
// times by -1 to make positive value
( $maxValue - ( $decreaseValue * -$i ) ) * -1
}
}我已经在js中测试了上面的(使用相对语法),它产生了所需的结果( jsBin example )。希望这能有所帮助
https://stackoverflow.com/questions/13605375
复制相似问题