2016-04-18 89 views
-1

這是我的代碼:jQuery的窗口中設置寬度

$(function() { 
    checkWindowSize(); 

    function checkWindowSize() { 

     var elWidth = $("#elId").outerWidth(), 
      elHeight = $("#elId").outerHeight(); 


     $(window).innerWidth(elWidth); 
     $(window).innerHeight(elHeight); 
    } 
}); 

我希望每次當我打電話checkWindowSize()函數的時間來調整瀏覽器窗口。但我注意到窗口對象的resize函數不起作用。 如何調整瀏覽器窗口大小?

+0

只能調整其大小與'動態創建一個窗口的window.open()'。而且您無法調整打開多個選項卡的窗口大小。請參閱https://developer.mozilla.org/en-US/docs/Web/API/Window/resizeTo – Barmar

+0

這是我的情況:由window.open打開的窗口。但是,我必須調整它的大小取決於內容。 – Anastasiia

回答

0

好吧,我找到了答案

我的新功能:

function checkWindowSize() { 

    var elWidth = $("#elId").outerWidth(), 
     elHeight = $("#elId']").outerHeight(), 

     browserElements = window.outerHeight - window.innerHeight; 

    window.resizeTo(elWidth, elHeight + browserElements); 

} 
相關問題