How can I make a jQuery functions execute on load and on window resize?

懵懂的女人 提交于 2019-12-25 03:30:16

问题


How can I make this function run on load and on window resize? thanks.

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

回答1:


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);

});


来源:https://stackoverflow.com/questions/25274141/how-can-i-make-a-jquery-functions-execute-on-load-and-on-window-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!