2014-09-06 46 views
3

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聲明(<!DOCTYPE html>
  • 刪除在專區內的所有內容問題
  • 刪除js文件中除screen_height函數外的所有內容
  • 刪除在SCREEN_HEIGHT功能一切,除了$('.screen-height').css({'height': $(window).height() });
  • 做一個對的console.log和$(window).height()回報

獲得12191我難倒。據我所知,網站更新到WordPress 4.0時發生錯誤,但它並未使用WordPress中捆綁的jQuery版本。任何和所有的幫助表示讚賞。

+0

爲什麼不使用'window.outerHeight'或'window.innerHeight'? – mddw 2014-09-06 09:45:39

+0

此外,您應該將googleanalytics腳本移到HTML中 - 當前您的頁面在doctype聲明之前以腳本開始,並且在沒有關閉body和html(=末尾丟失)的情況下結束。 – 2014-09-06 09:57:10

回答

1

當doctype設置不正確時,jQuery將$(window).height()視爲$(document).height()

您使用了正確的文檔類型(<!DOCTYPE html>),但通過在其之前添加分析代碼,您已將其呈現爲無效。

將分析代碼移動到頭部,就在關閉</head>標記之前,它應該都可以正常工作。

編輯:我剛剛注意到你有兩個不同的分析代碼塊。擺脫頂部(第1行)的那個。

+0

太棒了,謝謝。分析代碼hade通過插件添加,我不知道客戶端已經安裝。取消激活它解決了這個問題。 – 2014-09-06 11:37:48

相關問題