LoginSignup
1
2

More than 5 years have passed since last update.

.eachで画像がそれぞれ縦長か判別

Posted at
check_size.js
$(function(){
    //shop_infoの画像がそれぞれ縦長か判別
  $('.shop_info li ').each(function(){
    //imgを制作
        let img = new Image();
        img.src = $(this).children('img').attr('src');
        //ソースから縦横サイズを取得
    let h = img.height;
    let w = img.width;
    //縦長であればtallクラスをつける
    if (h > w) {
            $(this).addClass('tall');
    }
  });
});
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2