when using (count/2) for giving background color in div, it applied for alternative boxes. But i want to give div background for first three boxes same color then for the next three boxes diff color then again for the next three boxes the first color then next three boxes the second color.
The alternative color should be applied for three boxes once. Please clarify this one
You can use modulo
var c;
if (count % 6 < 3)
// color one
c = '#fff';
else
// color two
c = '#ccc';
Or as a one-liner
var c = count % 6 < 3 ? '#fff' : '#ccc';
Try something like
k=0, Color=Red
while()
{
if(k == 3)
{
k=0;
if(Color == Red) Color=Green
else Color = Red
}
else
{
k++;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.