基于第n个elemet的div [英] stlying div's based on nth elemet
问题描述
我正在尝试在计算每3n + 3和3n + 4的高度后应用样式
I am trying to apply styles after calculating the height of every 3n+3 and 3n+4
$(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('landscape');
$('ul img:nth-child(3n+4)').addClass('landscape-2');
}
else if (result == 2460) {
$('ul img:nth-child(3n+3)').addClass('portrait');
$('ul img:nth-child(3n+4)').addClass('portrait-2');
}
else if (result == 1776) {
$('ul img:nth-child(3n+3)').addClass('landscape-portrait');
$('ul img:nth-child(3n+4)').addClass('landscape-portrait-2');
}
});
<ul>
<img height="546" src="images/landscape2.jpg">
<img height="1230" src="images/portrait.jpg">
<img height="1230" src="images/portrait.jpg" class="landscape-portrait">
<img height="546" src="images/landscape2.jpg" class="landscape-portrait-2">
<img height="546" src="images/landscape2.jpg">
<img height="1230" src="images/portrait.jpg" class="landscape-portrait">
<img height="1230" src="images/portrait.jpg" class="landscape-portrait-2">
<img height="1230" src="images/portrait.jpg">
<img height="546" src="images/landscape2.jpg" class="landscape-portrait">
<img height="546" src="images/landscape2.jpg" class="landscape-portrait-2">
<img height="546" src="images/landscape2.jpg">
</ul>
问题。这将计算img.first1 + img.first2的高度,然后将样式应用于每3n + 3 / 3n + 4。
我想计算img.first1 height + img.first2身高并根据结果应用样式。
然后我想计算img.first3 height + img.first4身高并根据结果应用不同的风格。
请注意不会有课程img.first它只是说明每3n + 3和3n + 4
帮助赞赏
Problem. This calculates the height of img.first1 + img.first2 then applys the style to every 3n+3/3n+4.
I want to calculate img.first1 height + img.first2 height and apply style based on result.
I then want to calculate img.first3 height + img.first4 height and apply different style based on result.
Please note there will be no class img.first it is just to demostrate every 3n+3 and 3n+4
Help appreciated
推荐答案
(< span class =code-keyword> function (){
var fl =
( ' ul img:nth-child(3n + 3)')。height();
var fr =
('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+4)').height(); var result = fl += fr; if (result == 1092) {
这篇关于基于第n个elemet的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!