0

I am trying to trigger an scroll event using class element. I tried multiple scenarios but no good.

enter image description here

Below are types of events tried...

jQuery(function($){
     $('[class="ag-body-container"]').bind('scroll',function() {
      alert("hai");
     });
 });

$(document).ready(function(){
        $(".ag-body-viewport-wrapper").bind('scroll',function() {
            alert("hai");
        });
});

$(document).on('scroll', '.ag-body-container', function(){ 
        console.log('scroll happened');
});

$(function() {
     $(".ag-body-container").on('scroll', function () { 
       console.log('scroll happened'); 
      });
});

$(".ag-body-container").bind('scroll', function() {
       console.log('Event worked');
}); 

Non of the above gives expected result.

3 Answers 3

1

you havent tried

$(document).ready(function(){
    $(document).on('scroll', '.ag-body-container', function(){ 
        console.log('scroll happened');
    });
});

OR

 $(document).ready(function(){
    $(window).on('scroll', '.ag-body-container', function(){ 
        console.log('scroll happened');
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

it will fire only if .ag-body-container is scrollable so if it is overflowed and you scroll it
0

try .on instead of .bind or you can use .scroll.

Because, .bind may be removed from future versions at any time. There is no reason to keep using .bind and every reason to prefer .on instead.

See jquery .bind() vs. .on()

Comments

0

The scroll event occurs when the user scrolls in the specified element.

The scroll event works for all scrollable elements and the window object (browser window).

if window is scrollable than the below code will fired.

 $(function() {
     $(window).on('scroll', function () { 
       console.log('scroll happened'); 
      });
});

but if you are trying to something like this.

 $(".ag-body-container").on('scroll', function () { 
       console.log('scroll happened'); 
      });

if the element identified by '.ag-body-container' is scrollable , then only event will be fired.

check the plunker : http://plnkr.co/edit/QCMSsfGgggjaHVWDdNp9?p=preview

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.