scrollTop()检测顶部而不是底部

时间:2015-07-13 14:17:52

标签: javascript jquery

当我想检测我的页面底部时,我使用此代码在测试文件中正常工作(链接如下):

$(window).scroll(function() {
    $(window).scrollTop() + $(window).height() == $(document).height(){
       alert(at bottom);
    }
}

但在我的最终文件中,完全相同的代码仅检测到滚动到顶部。谁能看到错误或提供更好的解决方案?

链接到测试文件:www.warthunder-skins.de/test/

链接到普通文件:www.warthunder-skins.de/skins/

2 个答案:

答案 0 :(得分:0)

检测TOP

   $(window).scroll(function() {
        if ($(window).scrollTop() == 0) {
           alert('at the TOP');
        }
    });

检测BOTTOM

$(window).scroll(function() {
    if ($(window).scrollTop() + $(window).height() == $(document).height()) {
       alert('at bottom');
    }
});

答案 1 :(得分:0)

这是因为页眉问题

的原因

当我在浏览器中查看来源时,这是您的页面前7行

<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"></head><body><br>
<title>Warthunder Skins</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="">

将这些行更改为!!!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Warthunder Skins</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="keywords" content="">
</head>
<body>

现在试一试!!!!

相关问题