我的页面内容是动态创建的,我正在尝试编写一个脚本来搜索容器“image-rounded”中的所有图像,如果它们不是正方形,则更改高度或宽度以使它们成为正方形(基于在最小边的大小上)。
到目前为止,这是我的脚本:
jQuery(function($) {
$('.wrapper-site').find('.image-rounded img').each(function () {
var round_image_width = $(this).width();
var round_image_height = $(this).height();
if(round_image_height > round_image_width) {
$(this).css('height', 'round_image_width');
} else {
$(this).css('width', 'round_image_height');
}
});
});
但目前这什么都不做。
最佳答案
$(this).css('height', 'round_image_width');
应该是
$(this).css('height', round_image_width);
同样的高度......发生在我们最好的:)
关于javascript - jQuery 将具有特定类别的所有图像调整为正方形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36251431/