问题
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