Jquery $(window).height()函数不返回实际的窗口高度 [英] Jquery $(window).height() function does not return actual window height

查看:143
本文介绍了Jquery $(window).height()函数不返回实际的窗口高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,当用户滚动到底部时,我需要动态加载ajax内容。问题是JQuery没有返回正确的窗口高度。我之前使用过这个函数,从未见过它失败,但由于某种原因,它将返回与文档高度相同的值。我在这里有测试页面:bangstyle.com/test-images

I have a page that I need to dynamically load ajax content when the user scrolls to the bottom. The problem is that JQuery is not returning the correct window height. I have used this function before and have never seen it fail, but for some reason it will return the same value as the document height. I have the test page here: bangstyle.com/test-images

我已经将警报编码为在页面加载时显示,并且每当用户在顶部下方滚动500px时:

I have coded the alert to display at page load, and also whenever the user scrolls 500px below the top:

function scroller() {

                        if($(window).scrollTop() > 500){

                        delay(function(){ //200ms wait
                                pagecounter++;
                                sideshow();
                                alert("window height: " + $(window).height() + " scrolltop: " + $(window).scrollTop() + " document height: " + $(document).height());

                                return false;
                            }, 200 );

                                    }
                            }

我之前试过发布这个但是我删除它,因为我没有得到解决方案。我希望可以发布我的测试页面的链接。顺便说一句,我已经在Mac Safari和Mac FF上测试了这个。我在其他页面上运行相同的代码,它工作正常。我觉得这个页面的dom必定会有一些东西导致JS失败,但不知道会是什么。

I tried posting this before but I deleted it as I didn't get a solution. I hope it is ok to post a link to my test page. BTW I have tested this on Mac Safari and Mac FF. I have run this same code on other pages and it works fine. I feel there must be something in the dom of this page that causes JS to fail, but no idea what that would be.

推荐答案

查看您的HTML源代码。
第一行应该是<!DOCTYPE html> 而你有< style> 标签代替。

Look at your HTML souce code. The first line should be <!DOCTYPE html> and you have <style> tag instead.

因此,您的文档似乎在Quirks模式下运行,jQuery无法计算正确的窗口尺寸。

So it seems that your document is running in Quirks Mode and jQuery can't calculate correct window dimensions.

这篇关于Jquery $(window).height()函数不返回实际的窗口高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆