search

Home  >  Q&A  >  body text

javascript - Questions about document.documentElement.scrollTop and document.body.scrollTop

Please help. . I just encountered a problem about the adaptation of document.documentElement.scrollTop and document.body.scrollTop. I read online that document.documentElement.scrollTop is used in standard mode. . But why do I test that the value of document.documentElement.scrollTop is always 0 in HTML5 standard mode, while document.body.scrollTop has a value?

为情所困为情所困2803 days ago866

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-07-05 10:43:05

    Different browsers process different results
    Poke me

    reply
    0
  • ringa_lee

    ringa_lee2017-07-05 10:43:05

    Browser compatibility issue.
    It is recommended to write
    let top = document.documentElement.scrollTop || document.body.scrollTop

    reply
    0
  • Cancelreply