S
S
Sergey2018-08-17 00:25:03
JavaScript
Sergey, 2018-08-17 00:25:03

Why doesn't $(window).scroll work for me in chrome?

Why in chrome console is undefined, but in other browsers - scrollbar data?

$(window).scroll(function(e) {
  console.log(e.pageY);
});


In firefox (working):
5b75eb8e579f9518720540.png

In chrome (not working - undefined):
5b75eba66f08d972820216.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
imdeveloper, 2018-08-17
@butteff

If you are using jQuery, then I recommend using the function $(document).scrollTop()and everything will work:

$(window).scroll(function(e) {
     console.log($(document).scrollTop());
});

N
Nikita, 2018-08-17
@Rema1ns

If without jq, then you can use the construction

var scrolled = window.pageYOffset || document.documentElement.scrollTop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question