Используя $(window).resize(functionA)
, как мне повторно запустить objectA без повторного запуска objectB при изменении размера?
objectB требует, чтобы objectA работал, потому что objectB использует $(this)
.
Здесь jQuery:
var objectA = $('.row').find('.noLimitBackgroundPNGAcontainer').resize().each(function() {
// Get on screen image
var screenImage = $(this).find('.imgWrapper>img');
// Create new offscreen image to test
var theImage = new Image();
theImage.src = screenImage.attr("src");
// Get accurate measurements from that.
var imageWidth = theImage.width;
var imageHeight = theImage.height;
//Finds tallest height out of all columns inside every row containing any image.
var objectB = $(this).find('.imgWrapper>img').each(function() {
var maxHeight = 0;
$(this).closest('.row').find('.evaluateHeight').each(function checkHeight() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
};
});
});
//these variables find the correct img width and img height for imitating object-fit CSS.
var actualIMGwidthWhenConstrainedByColumnHeight = maxHeight * (imageWidth / imageHeight);
var imgContainerWidth = $(this).closest(".noLimitBackgroundPNGAcontainer").width();
var actualIMGheightWhenConstrainedByColumnWidth = ($(imgContainerWidth)) * (($(imageHeight)) / ($(imageWidth)));
//This code imitates the object-fit CSS feature.
if (imgContainerWidth > actualIMGwidthWhenConstrainedByColumnHeight) {
$(this).closest(".backgroundPNGAfix").width(actualIMGwidthWhenConstrainedByColumnHeight);
$(this).height(maxHeight);
} else {
$(this).closest(".backgroundPNGAfix").width('100%');
$(this).height(actualIMGheightWhenConstrainedByColumnWidth);
};
});
$(window).resize(objectA).not(objectB);