PageXOffset is not available only on Chrome for Android.

Asked 2 years ago, Updated 2 years ago, 63 views

The rect.left+window.pageXOffset+"px" value is only Chrome for android different from other browsers.
IE11, FireFox, Chrome for windows, FireFox for android get the expected value.
You can't get the expected value only when you zoom in on Android and scroll.
Is this the chrome for Android specification?
Can you find something like the javascript specification for chrome for android online?
I don't know how to check it myself.Thank you for your cooperation.

javascript android google-chrome

2022-09-30 19:44

1 Answers

On Android, the browser may return 0s for window.pageXOffset or window.pageYOffset.

I have a similar question in my home SO.
It is recommended that you temporarily save the acquired values

var cachedPosition;

window.addEventListener("scroll", function(){
  varposition=window.pageYOffset;

  console.log('position:'+position);

  if(position===0){
    position = cachedPosition;
  } else{
    cachedPosition=position;
  }

  console.log('cached position:'+cachedPosition);
}, false);


2022-09-30 19:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.