我的页面内容是动态创建的,我正在尝试编写一个脚本来搜索容器中的所有图像'图像舍入'如果它们不是正方形,则将高度或宽度更改为使它们成方形(基于最小边缘的大小)。
到目前为止,这是我的脚本:
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');
}
});
});
但目前这没有任何作用。
答案 0 :(得分:4)
$(this).css('height', 'round_image_width');
应该是
$(this).css('height', round_image_width);
相同的高度...发生在我们最好的人身上:))