javascript - jQuery 'scroll' not firing -


i have following:

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

i can $('body').scrolltop(400) , body scrolls fine, alert never called when manually scroll. causing this?

don't use $('body'), either $(document) or $(window) catch scroll, this:

$(document).ready(function() {     $(document).scroll(function() {     console.log('scrolled ' + $(this).scrolltop());   }) }); 

here's working jsfiddle: https://jsfiddle.net/4rrm3myl/1/


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -