Scroll event is not firing while scrolling the ul
. I'm using jQuery version 1.10.2. As I'm loading the ul
from an ajax page, I couldn't use $('ulId').on('scroll', function() {});
or other live methods. Please help me to find a solution.
$(document).on( 'scroll', '#ulId', function(){
console.log('Event Fired');
});
I know that this is quite old thing, but I solved issue like that: I had parent and child element was scrollable.
The issue I had is that I didn't know when the child is loaded to DOM, but I kept checking for it every second.
NOTE:this is useful if it happens soon but not right after document load, otherwise it will use clients computing power for no reason.
You probably forgot to give
#
before id for id selector, you need to give#
beforeid
ie isulId
You problably need to bind scroll event on div that contains the ul and scrolls. You need to bind the event with div instead oful
Edit
The above would not work because the scroll event does not bubble up in DOM which is used for event delegation, see this question why doesn't delegate work for scroll?
But with modern browsers > IE 8 you can do it by other way. Instead of delegating by using jquery you can do it using event capturing with java script
document.addEventListener
, see how bubbling and capturing work in this tuturial.Live Demo
If you do not need event delegation then you can bind scroll event directly to the ul instead of delegating it through
document
.Live Demo
Can you place the #ulId in the document prior to the ajax load (with css display: none;), or wrap it in a containing div (with css display: none;), then just load the inner html during ajax page load, that way the scroll event will be linked to the div that is already there prior to the ajax?
Then you can use:
obviously replacing ulId with whatever the actual id of the scrollable div is.
Then set css display: block; on the #ulId (or containing div) upon load?
Using VueJS I tried every method in this question but none worked. So in case somebody is struggling whit the same:
Another option could be:
Reference: Here
see this post - Bind scroll Event To Dynamic DIV?