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

199
Vistas
jQuery 'scroll' not firing

I have the following:

 var onScroll = function () {
        alert('scroll');
 };
 scrollArea = $('body');
 scrollArea.on('scroll', onScroll);

I can do $('body').scrollTop(400) and the body scrolls fine, but the alert is never called when I manually scroll. What could be causing this?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

When you scroll the page, it's window that is scrolling not the body. So change it to $(window).on('scroll', onScroll);

EDIT: If you want to bind it to body specifically you may do it using document.body.onscroll = onScroll;. But make sure you do not bind any onscroll event to window in that case. If you do so, document.body.onscroll will be ignored and window.onscroll will be listened to.

Check this in action at the fiddle link here.

over 4 years ago · Santiago Trujillo Denunciar

0

Don't use $('body'), but either $(document) or $(window) to catch the scroll, like this:

$(document).ready(function() {
    $(document).scroll(function() {
    console.log('Scrolled to ' + $(this).scrollTop());
  })
});

Here's a working jsFiddle: https://jsfiddle.net/4rrm3myL/1/

over 4 years ago · Santiago Trujillo 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