运行 $(window).height()
时无法获得正确的值上www.presenskonferens.se 。在所有浏览器中都是一样的。
这是我正在使用的代码:
// Screen height sections
$(function() {
function screen_height() {
$('.screen-height').css({'height': $(window).height() });
}
screen_height();
window.addEventListener("orientationchange", screen_height );
$(window).resize( screen_height );
});
这是我尝试过的:
- 使用正确的文档类型声明 (
<!DOCTYPE html>
) - 删除相关 div 中的所有内容
- 删除js文件中除screen_height函数之外的所有内容
- 删除 screen_height 函数中除
$('.screen-height').css({'height': $(window).height() });
之外的所有内容 - 为
$(window).height()
创建console.log并获得 12191 返回
我被难住了。据我所知,该错误是在网站更新到 WordPress 4.0 时发生的,但它没有使用 WordPress 中捆绑的 jQuery 版本。感谢任何和所有的帮助。
最佳答案
当文档类型设置不正确时,jQuery 会处理 $(window).height()
与 $(document).height()
相同.
您使用了正确的文档类型 ( <!DOCTYPE html>
),但通过在其前面添加分析代码,您已使其无效。
将分析代码移至头部,就在结束之前 </head>
标签,它应该一切正常。
编辑:我刚刚注意到您有两个不同的分析代码块。去掉最上面的那个(第 1 行)。
关于jquery - $(window).height() 返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25698856/