body.scrollTop is deprecated in strict mode. Please use 'documentElement.scrollTop' if in strict mode and 'body.scrollTop' only if in quirks mode.

后端 未结 1 1609
自闭症患者
自闭症患者 2021-01-05 17:59

I\'m receiving the error:

body.scrollTop is deprecated in strict mode. Please use \'documentElement.scrollTop\' if in strict mode and \'body.scrollTop\' only if in q

相关标签:
1条回答
  • 2021-01-05 18:24

    Dagg Nabbit gave the solution. Change

    $('html,body').animate({scrollTop: divTag.offset().top},'slow');
    

    to

    $('html').animate({scrollTop: divTag.offset().top},'slow');
    

    if you want to avoid the deprecation warning in Chrome. (Why is body.scrollTop deprecated?)

    It works because documentElement is the html node:

    $('html')[0] === document.documentElement //-> true
    $('body')[0] === document.body            //-> true
    

    But your code is working now (albeit with a warning) and it will keep working when Chrome removes the "quirky" behavior. You shouldn't change your code if you want to continue supporting browsers that use body.scrollTop to represent the scrolling viewport in standards mode (older Chrome and Safari, I think).

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