Service Portal - window.addEventListener('scroll') not working?

Vegard S
Kilo Sage

I need to check on a service portal if the user scrolls down a certain amount, but it doesn't seem like window.addEventListener('scroll', function(e) is firing. 

var last_known_scroll_position = 0;
var ticking = false;
console.log('this does appear in the console log');

function doSomething(scroll_pos) {
  // Do something with the scroll position
	console.log('this does not appear in the console log');
}

window.addEventListener('scroll', function(e) {
  last_known_scroll_position = window.scrollY;
	console.log('not this either');
  if (!ticking) {
    window.requestAnimationFrame(function() {
      doSomething(last_known_scroll_position);
      ticking = false;
    });

    ticking = true;
  }
});

Does anyone have any idea?

2 REPLIES 2

Justin77
Mega Guru

I know window has some issues in service portal, you might need to use top instead/in addition.  Alternatively, you could always use AngularJS.  A quick google search brought me to this post, might be what you're looking for: https://stackoverflow.com/questions/44100053/how-to-bind-scroll-event-on-element-in-angularjs-direct...

Prateek kumar
Mega Sage

Please take a look at below:

https://community.servicenow.com/community?id=community_question&sys_id=eab383a5dbd8dbc01dcaf3231f96...


Please mark my response as correct and helpful if it helped solved your question.
-Thanks