0
I have a list of 200 lines, and each line has its id.
I would like to capture with javascript, the id of each line when scrolling down the page.
The list is assembled this way:
<ol id="noticias">
<li id="geral" class="area">
Conteudo
</li>
<li id="esportes" class="area">
Conteudo
</li>
<li id="mundial" class="area">
Conteudo
</li>
<li id="tecnologia" class="area">
Conteudo
</li>
</ol>
Trying to put it another way.
I set up an array, in which, each entry represents a row of my list. In each input there are two fields, one with line height and the other with line id.
It’s like this:
var lists = [ [45, 'news'], [50,'technology'], [100, 'world''] ];
With each scroll on the page, the program captures the body height, and with the body height value, it analyzes which field I am in the array
Solution:
I managed using this function:
$(window).on("scroll resize", function() {
var altura_body = $(window).scrollTop();
for (var i = 0; i <= numero_de_linhas; i++) {
if (altura_body >= listas[i][0] && altura_body <= listas[i + 1][0]) {
$(".mostra_id").html(listas[i][1]);
}
}
});
What is the HTML of this list? No need to put the 200.
– Sam
I captured the line heights and id’s in an array array_altura_lines, hence using $(window). on("scroll resize", Function() {}, I would like to compare the height of the "body" with the row array_altura_line and know which index it fits into
– Alê Moraes
The ids I have already captured and are in an array, each member of the array has two fields, one with line height and the other with id
– Alê Moraes
So I would like with the scroll, to see the height of the body (I already did this, in an altura_body variable), with this value of the altura_body it should scan this array in the field of line heights, and find in which index it is
– Alê Moraes
I want the id of the list on the screen to appear in a div
– Alê Moraes
I rewrote the question, see if I can make it clearer
– Alê Moraes
Just the name of the id on the screen, you know? When I descend the panel and arrive in the field of "technology", it appears in the field that I am in the line of "technology"
– Alê Moraes
that! Explaining otherwise: I have a variable x = 55, how to compare with this array var lists = [ [45,'news'], [50,'technology'], [100, 'world'] ]; and see which index it fits into
– Alê Moraes
With this array construction is complicated. Could make an object.
– Sam
You need to edit the question and explain everything right. It’s confusing. The code I have ready. The ids will appear in the console as the list items appear, but tb appear the ids of the ones that are already visible.
– Sam
Thanks man, I’ll try to rewrite to see if it gets clearer, but thanks for the help
– Alê Moraes