scrollTop not working in Safari

南笙酒味 提交于 2019-12-25 16:33:15

问题


Firs time this is happening to me, i'm aware that scrollTop have some issues with some browsers but this time is only in Safari, Firefox and Chrome are ok. Here is my code

$(window).scroll(function()
{
    var s = $('html, body').scrollTop();
    console.log(s) //ok on FF and Chrome, but Safari returns 0
}

回答1:


Sadly you must check for both the <html> and <body> element separately.

$(window).scroll(function()
{
    var s = $('html').scrollTop() || $('body').scrollTop();
    console.log(s);
});


来源:https://stackoverflow.com/questions/26242982/scrolltop-not-working-in-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!