El script que encontró complicó demasiado el problema. Los siguientes trabajó para mí:
$(function(){
// Cache reference to our container
var $container = $("#container");
// A function for updating max-height
function updateMaxHeight() {
$container.css("max-height", $(this).height() - 100);
}
// Call updateMaxHeight when browser resize event fires
$(window).on("resize", updateMaxHeight);
});
Una advertencia es que el evento resize se llama mucho cuando cambiar el tamaño del navegador; no se llama solo después de que el navegador ha sido redimensionado. Como resultado, puede hacer que se llame a la función de devolución de llamada cientos de veces; generalmente esta es una mala idea.
La solución sería acelerar o atenuar el evento. La limitación significa que no permitirá que la devolución de llamada se active más de x veces en un lapso de tiempo (tal vez 5 veces por segundo). La eliminación de rebotes significa que se activa la devolución de llamada después de que ha pasado un cierto lapso de tiempo desde el último evento de cambio de tamaño (espere hasta 500 milisegundos después de un evento de cambio de tamaño).
jQuery no admite actualmente una opción de acelerador o antirrebote, aunque hay complementos. Other popular libraries you may have used do have these features, tales como subrayado:
$(function(){
// Cache reference to our container
var $container = $("#container");
// A function for updating max-height
function updateMaxHeight() {
$container.css("max-height", $(this).height() - 100);
}
// Version of updateMaxHeight that will run no more than once every 200ms
var updateMaxHeightThrottled = _.throttle(updateMaxHeight, 200);
// Call updateMaxHeightThrottled when browser resize event fires
$(window).on("resize", updateMaxHeightThrottled);
});