I am trying to count the number of rows using the value "offset (). Top" of each of the articles on the page. The first two conditions are met, but the last, to determine the next line, is never fulfilled, I can
var datarow = 1;
var rowNum = 0;
if(prev.length == 0){
datarow = 1;
$this.attr("data-row", datarow);
}
else if(prev.length > 0 && $this.offset().top == prev.offset().top){
$this.attr("data-row", datarow);
}
else if(prev.length > 0 && $this.offset().top != prev.offset().top){
rowNum++;
$this.attr("data-row", datarow + rowNum);
}
console.log("rowNum is:" + rowNum);
I'm new to using jQuery, so I apologize for any beginner errors. Here is a fiddle to show you what I'm trying to accomplish, and so that the code above has more context. https://jsfiddle.net/JackofD/a598Lp0c/1/
and the full-screen result https://jsfiddle.net/JackofD/a598Lp0c/1/embedded/result/
Any help well appreciated Thanks in advance
P.S , row-row. , ( ) (, data-row = "2" ).