Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

85
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda