如何在加载和窗口大小调整时执行jQuery函数?

时间:2014-08-12 21:13:32

标签: jquery responsive-design window-resize

如何在加载和窗口调整大小时运行此功能? 感谢。

jQuery(function( $ ) {
var headerHeight = $("#header").outerHeight();
var viewportHeight = $(window).height();
var elementNewHeight = viewportHeight - headerHeight;
$(".fullHeightThis").outerHeight(elementNewHeight);
});

1 个答案:

答案 0 :(得分:0)

jQuery(function( $ ) {
    function someStuff(){
      var headerHeight = $("#header").outerHeight();
      var viewportHeight = $(window).height();
      var elementNewHeight = viewportHeight - headerHeight;
      $(".fullHeightThis").outerHeight(elementNewHeight);
    }
    someStuff(); //call immediately

    $(window).on('resize', someStuff);

});