jQuery scrollTop() returns 0 for all elements

后端 未结 3 1269
离开以前
离开以前 2020-12-31 09:46

At my job we have a one page site I created with AngularJS.
We\'re using the ui-router plugin (version 0.2.0).
Recently I\'ve noticed that when moving from one state

相关标签:
3条回答
  • 2020-12-31 10:02

    From the console, try

    console.log(frames)
    console.log(frames.top.scrollY)
    

    If window.scrollY is showing 0, then the reference frame must not be the window. Do you have any iframes on the page? console.log of frames will show the list of frames on the page.
    Hope that helps.

    0 讨论(0)
  • 2020-12-31 10:04

    My code is happend this problem too, and I found a body{overflow: hidden;} is the reason, I remove "overflow: hidden;" and all is well.

    0 讨论(0)
  • 2020-12-31 10:13

    As @Hans commented, there wasn't actually a problem. I had a wrapping element, that was positioned absolute with:

    top:0;
    bottom:0;
    left:0;
    right:0;
    overflow:auto
    

    So The window's scrollTop was always 0, and the scrollbar actually belonged to the wrapping element.

    Since I could't get rid of the wrapping element's positioning, I used ui-router's $stateChangeSuccess event, and manually scrolled the wrapping element to the top.

    0 讨论(0)
提交回复
热议问题