Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
How can I find the current scroll position of a chart in Javascript?

I have a chart that is scrollable

enter image description here

I am trying to fire off a function when the user has reached the bottom of the table bordered in red.

The approach I took is to find the height of the chart which is 1520px.

Then I will need a way to find the pixel of the current scroll position, but there is no such method as element.currentScrollPosition

How can I find the current scroll position of the chart?

I will be subtracting the position from 1520px to see if the user has scrolled to the bottom if the result is 0.

This is the code for each row:

function getScrollPosition() {
    const plTable = document.getElementById('plTable');
    const x = plTable?.scrollHeight;
    const y = plTable?.scrollTop;
    const z = plTable?.offsetHeight;
    console.log(x);
    console.log(y); // scroll position from top
    console.log(z);
  }


// chart component

return (
  //... skip some code
</TableHead>
                  <TableBody>
                    <div
                      id="plTable"
                      onClick={getScrollPosition}
                      style={{ border: '1px solid red' }}
                    >
                      {lineItems.map((lineItem, i) => (
                        <TableRow key={lineItem.id}>
                          <LineItemRow
                            i={i}
                            id={lineItem.id}
                            reportName={reportName}
                            level={lineItem.level}
                          />
                        </TableRow>
                      ))}
                    </div>
                  </TableBody>
                </Table>
              </Scrollbar>
            </CardContent>
          </Card>
)

I didn't find scrollTop and offsetHeight too useful, so you can ignore that.

Also scrollTop always gives 0 no matter where I scroll then click

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The best way to deal with scrolling is by using an Observer API it is better for your website performance.

This is what you must do:

//Add an elemnt in your html with the class of "end" at the end of the chart
//I recommend adding an empty div with the class of "end" and setting it's opacity to 0
const end =document.querySelector(".end");

const endObserver = new IntersectionObserver(function(entries){
    const [entry] = entries;
    if(entry.isIntersecting === false)
    {
    //Put what you want to happen if the end is NOT visible
    }
    else{
    //Put what you want to happen if the end is visible
    //For instance firing your function
    }
    },{root:null,threshold:1});
endObserver.observe(end);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda