问题描述
我目前正在申请基于第2个孩子身高的总和的css课程,例如,如果第2个孩子的身高+第3个孩子的身高等于x以上,则添加特定的课程。
这是我要计算的javascript -
I am currently applying a css class based on the sum of 2 nth childs height for example if height of 2nd child + height of 3rd child equals more than x add specific class.
This is my javascript to calculate -
<script>
$(function() {
var fl = $('ul img:nth-child(3n+3)').height();
var fr = $('ul img:nth-child(3n+4)').height();
var result = fl += fr;
if (result == 1092) {
$('ul img:nth-child(3n+3)').addClass('style1a');
$('ul img:nth-child(3n+4)').addClass('style1b');
}
else if (result == 2460) {
$('ul img:nth-child(3n+3)').addClass('style2a');
$('ul img:nth-child(3n+4)').addClass('style2b');
}
else if (result == 1776) {
$('ul img:nth-child(3n+3)').addClass('style3a');
$('ul img:nth-child(3n+4)').addClass('style3b');
}
});
</script>
这几乎完美无缺,它计算出3n + 3和3n + 4的第一次迭代的高度并应用了一种风格对所有3n + 3。
但是,我需要改变我的javascript以计算3n + 3和3n + 4的每次迭代的高度而不仅仅是第一次迭代然后应用样式。
SUM的li(3)+ li(4)添加样式,SUM的li(6)+ li(7)添加样式。
提前致谢!
This almost works perfectly, it calculates the height of THE FIRST ITERATION OF 3n+3 and 3n+4 and applies a style to all 3n+3.
However, i need to alter my javascript to calculate the height of EVERY ITERATION of 3n+3 and 3n+4 rather than just the first iteration and then apply the style.
SUM of li(3)+li(4) add style, SUM of li(6)+li(7) add style.
Thanks in advance!
推荐答案
这篇关于Javascript造型第N个孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!