[英]jQuery resize all images with a certain class to be square
我的頁面內容是動態創建的,我試圖編寫一個腳本來搜索容器中“圖像四舍五入”的所有圖像,如果它們不是正方形,則更改高度或寬度以使其正方形(根據大小)最小的邊緣)。
到目前為止,這是我的腳本:
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);
身高相同...屬於我們中最好的:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.