【发布时间】:2014-10-31 04:09:33
【问题描述】:
在www.presenskonferens.se 上运行$(window).height() 时,我无法获得正确的值。在所有浏览器中都是一样的。
这是我正在使用的代码:
// 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 版本。感谢您提供任何和所有帮助。
【问题讨论】:
-
为什么不使用
window.outerHeight或window.innerHeight? -
此外,您应该将 googleanalytics-script 移动到 HTML 中 - 目前您的页面以 doctype-declaration 之前的脚本开始,并且在不关闭 body 和 html 的情况下结束(=
标签: jquery wordpress window height