I've written the following jQuery plugin, which looks for all elements with the class "stretch", then identifies child elements with the class "stretch_this" and makes them all the height of the tallest "stretch_this" element within the parent.
$(document).ready(function () {
stretchHeight()
});
$(window).resize(function () {
stretchHeight()}
);
function stretchHeight() {
$('.stretch').each(function() {
var maxHeight = -1;
jQuery(this).find(".stretch_this").each(function() { //Resets the height so that it can work again on a resize.
$(this).height('auto');
});
jQuery(this).find(".stretch_this").each(function() {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
jQuery(this).find(".stretch_this").each(function() {
$(this).height(maxHeight);
});
}
)
}
It runs on the page load, and also whenever the page is resized as my overall layout is responsive and the height of the elements may change.
This works as expected, except when I refresh a page in Chrome, it reduces all image heights stretched in this way to 1px; this doesn't occur in IE. Loading the page afresh in Chrome (that is, hitting return in the address bar rather than hitting refresh) works fine - the elements resize as expected.
Why would this be? Is it an error in my code, or a quirk of Chrome? Is there any way around it. The plugin is deployed as part of a WordPress theme, if that matters.