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

208
Vistas
How to add dynamic overlay indicators for horizontal scrolling

One of the most self-explanatory ways to let the user know that an element is scrollable is to use some sort of fading overlay on the scrollable ends of a container. I wonder how could this be done in a clean way.

I want the elements to have overlay only when there is more content to scroll to, I've seen examples which had stationary faded overlays but those are imperfect IMO.

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

0

You can use ::before and ::after pseudo elements that are positioned absolutely. Here is the structure:

<div className="outer-container"> <!-- overflow-x: hidden -->
  <div className="inner-container"> <!-- flex & overflow-x: scroll -->
    <div>1</div>
    <div>2</div>
    <div>3</div>
    ...
  </div>
</div>
.outer-container {
  overflow-x: hidden;
  position: relative;
}
.outer-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: linear-gradient(to right, #fff, transparent);
  width: 3rem;
}
.outer-container::after {
  /* same */
  right: 0;
  background: linear-gradient(to left, #fff, transparent);
  /* same */
}
.inner-container {
  display: flex;
  flex-direction: row;
  overflow-x: scroll;
}

The reason we use two containers is that we need to keep the absolute elements (::before & ::after) stationary and prevent them from moving with the scrollable inner container.

Also to let the user know that s/he is at the end of the element boundaries, we can use the logic below:

  • show left overlay when: .scrollLeft > 0
  • show right overlay when: .offsetWidth + .scrollLeft < .scrollWidth

So that when the user scrolls to the beginning or end of the scrollable container, those overlays hide.

I made an example using react and styled-components, you can see it here: https://codesandbox.io/s/horizontal-scroll-with-overlay-elements-uhec0?file=/src/App.tsx

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