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

87
Vistas
Dynamic scrollbar with height connected to Y scroll coordinates

I created two components 'DynamicScrollBarContainer' and 'DynamicScrollBar'.

I'm trying to get the nested component to have a dynamic height connected to the vertical scrolling of the page, and by having two different background-color the container gets filled or emptied as the user scrolls up or down on the page.

import styled from 'styled-components';

export const DynamicScrollbarContainer = styled.div`
    position: fixed;
    right: 5%;
    top: 35%;
    width: 2px;
    height: 300px;
    background-color: rgba(255,255,255,0.5);
   
    @media ${(props) => props.theme.breakpoints.xl} {
        display: none;
    }
`;

export const DynamicScrollbar = styled.div`
    width: 100%;
    height: 0%;   // this is the value I'd need to get dynamic
    background-color: #ffffff;
`
import React from 'react';

import { DynamicScrollbarContainer, DynamicScrollbar } from './ScrollbarStyles';

const ScrollBar = () => (
  <DynamicScrollbarContainer>
    <DynamicScrollbar />
  </DynamicScrollbarContainer>
);

export default ScrollBar;

Anyone has any ideas? I have been messing with window.scrollY and other stuff but can't seem to do it properly

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

0

That's a BAD idea. Had to spend hours fixing problems with stuff like this at work. Some still standing. Your should really consider other options before doing something like this.

But, if you really have to, something like this should get you started.

const ScrollBar = () =>
  const [a, s] = useState(0);
  useEffect(() => {
    const c =  () => s(window.scroll /* I don't remember the prop, something like this */);
    // remember to add the other scroll events
    window.addEventListener('scroll',c)
    return () => window.removeEventListener(c);
  }, []);
  <DynamicScrollbarContainer>
    <DynamicScrollbar scroll={a} />
  </DynamicScrollbarContainer>
);
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