[英]jQuery resize all images with a certain class to be square
My page content is dynamically created, I am trying to write a script that searches for all images in a container 'image-rounded', and if they are not square, change either the height or width to make them square (based on the size of the smallest edge). 我的页面内容是动态创建的,我试图编写一个脚本来搜索容器中“图像四舍五入”的所有图像,如果它们不是正方形,则更改高度或宽度以使其正方形(根据大小)最小的边缘)。
Here is my script so far: 到目前为止,这是我的脚本:
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');
}
});
});
But currently this does nothing. 但这目前无能为力。
$(this).css('height', 'round_image_width');
should be 应该
$(this).css('height', round_image_width);
Same for the height... Happens to the best of us :) 身高相同...属于我们中最好的:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.