How to change an image path based on screen width?

前端 未结 6 1573
天涯浪人
天涯浪人 2020-12-13 01:06

I\'m trying to change the folder that my images are read from depending on the window width.

I have two folders that contain the different image sizes and I\'m wonde

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 01:34

    You Can use resize()

    $(window).resize(function() {
    if($(window).width() < 310 ) {
       $('img').attr('src','folder1'+filename);
    }
    if($(window).width() > 310 ) {
       $('img').attr('src','folder2'+filename);
    }
    

    });

提交回复
热议问题