jQuery: Set Image Height Based on Width for .sj_post_pic Element
To get the width of the '.sj_post_pic' element and set its height using jQuery, you can use the following code:
$(window).on('load resize', function () {
var postPicWidth = $('.sj_post_pic').width();
$('.sj_post_pic').css('height', postPicWidth);
});
This code will execute when the window is loaded or resized. It will get the width of the '.sj_post_pic' element using the width() function and then set its height equal to its width using the css() function.
原文地址: https://www.cveoy.top/t/topic/ngIa 著作权归作者所有。请勿转载和采集!