scrollTop not working in Safari

2019-09-17 02:58发布

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条回答
Viruses.
2楼-- · 2019-09-17 03:13

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

$(window).scroll(function()
{
    var s = $('html').scrollTop() || $('body').scrollTop();
    console.log(s);
});
查看更多
登录 后发表回答