2013-03-05 142 views
-4

我在解決此問題時遇到問題。我使用jQuery來調用resizeWindow函數,以便在瀏覽器窗口重新調整大小時運行。 resizeWindow函數按預期工作,但是,調整瀏覽器窗口大小似乎不會調用該函數再次運行。調整窗口大小後調用函數的問題

$(document).ready(function(){ 
    //Bind the window onresize event 
    $(window).bind('resize', resizeWindow); 

    //Call resizeWindow() function immediately to intially set elements 
    $(window).bind('load', resizeWindow); 
}); 

function resizeWindow(){ 
    //Find all the container parent objects 
    $('.container').each(function(){ 
      //Initialize the height variable 
      var maxHeight = 0; 

      //Cache the jQuery object for faster DOM access and performance 
      var $borders = $(this).find('.border'); 

      //Find all the border child elements within this specific container 
      $borders.each(function(){ 
        //Get current element's height 
        var thisHeight = $(this).height(); 

        //Check if the current height is greater than the max height thus far 
        //If so, change max height to this height 
        if (thisHeight>maxHeight) maxHeight = thisHeight; 
      }); 

      //Now that we have the maximum height of the elements, 
      //set that height for all the .border child elements inside the parent element 
      $borders.height(maxHeight); 
    }); 
} 
+1

你可以建立一個小提琴證明你的問題?你的裝訂似乎沒有問題。 – 2013-03-05 15:48:28

+0

我沒有任何問題,使其按預期工作。小提琴會很可愛。 – 2013-03-05 15:49:46

+0

該功能在您的頁面中調用。放一個斷點看看它。 – 2013-03-05 15:50:57

回答

2

我相信你手動設置邊界的高度時,該函數首先調用它時,窗口大小調整停止大小。

嘗試加入這一行var $borders之後:

$borders.css({height:'auto'}); 
+0

這個技巧。謝謝! – Rich 2013-03-05 15:58:20

+0

很高興能幫到你! – 2013-03-05 15:59:42