0

I'm developing the popup window of my Chrome extension. I bind a callback in scroll event of a div with selector like this:

$('#activity-tab .activity-list').bind('scroll', () => {
                    if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight){
// My code goes here
}
);

But it interprets this as the Window in popup, not the element with selector itself. I have to change my code into this to make it work properly:

But

$('#activity-tab .activity-list').bind('scroll', () => {
                    let element = $('#activity-tab .activity-list');
                    if (element.scrollTop() + element.innerHeight() >= element[0].scrollHeight){
// My code goes here
}
);

Why doesn't this work properly in Chrome popup environment?

necroface
  • 3,365
  • 10
  • 46
  • 70
  • 1
    Nothing to do with "Chrome popup environment" - learn the difference between `function` and `arrow function` ... they are not always interchangeable ... in this case they are not, as `this` works differently in arrow functions – Jaromanda X Apr 11 '18 at 03:35
  • 1
    Because you used an arrow function, which doesn’t have its own `this`. – Ry- Apr 11 '18 at 03:35

0 Answers0