简体   繁体   中英

Does the value of window.scrolltop() change when toolbar/addressbar on mobile devices collapses

I am doing some calculations with $(window).scrollTop(); , element.innerHeight(); , $(window).height(); , element.offset().top; . And i've noticed that the result is different on mobile devices due to the toolbar from chrome and safari. My question is do any of those values change when the toolbar collapses and what can i do against it.

I had the same issue in the past, and solved it by setting the position as fixed for the body . Maybe that will help you as well.

html {
  overflow: hidden;
  width: 100%;
}
body {
  height: 100%;
  position: fixed;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
}

I found a very similar question here , also there is a jQuery.documentSize solution on github which detects the real width and height of the document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM