如何根据img高度更改img宽度

Luk*_*kas 0 jquery height resize image width

我需要根据img高度更改img宽度.我使用了jQuery height属性,但它不起作用.请参阅下面的功能.

$(function imagesSizer(){
    var img = document.getElementsByClassName('.offer_img');
    if  ($('.offer_img').height() < 210) {
         $('.offer_img').css('width','360px')
    }
});
Run Code Online (Sandbox Code Playgroud)

Nic*_*tti 5

你应该试试

//Wait until the DOM is ready
$(function(){
    //get all images and iterate over them
    $('.offer_img').each(function(){;
        //if the height of this img is < 210
        if  ($(this).height() < 210) {
            //set the width to 360
             $(this).width(360);
        }
    });
});
Run Code Online (Sandbox Code Playgroud)