[英]HAML each loop add additional classes to nth elements
I'm trying to build a large gallery with different sized tiles and was wondering how can I accomplish with a HAML each loop the following result? 我试图用不同尺寸的瓷砖建造一个大型画廊,并且想知道如何使用HAML每个循环完成以下结果?
.box.box-large
%img
.box.box-medium
%img
.box
%img
.box
%img
.box.box-large
%img
.box.box-double
%img
.box.box-full
%img
.box
%img
.box
%img
- n.times do
.box{class: decide_class}
%img
Here n is the integer number. 这里n是整数。 N times the loop will be running. N次循环将运行。 now in your Create a helper method named decide_class and return appropriate class for that loop 现在,在您的名为helper_class的帮助器方法中,并为该循环返回适当的类
def decide_class
if (some condition to decide class)
'box-large' # return css class name as a string
else
'' # return empty string if you don't want to apply any class
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.