图片自动调整宽度适应页面

$("#baiduContent img").each(function (i) {
  var img = $(this);
  var realWidth;
  //var realHeight;
  $("<img/>").attr("src", $(img).attr("src")).load(function () {
    realWidth = this.width;
    //realHeight = this.height;
    if (realWidth >= 300) {
      $(img).css("width", "100%").css("height", "auto");
      }
    //else {       //$(img).css("width", realWidth + 'px').css("height", realHeight + 'px');     //}   }); });

 

posted @ 2019-06-14 00:01  VincentZhou  阅读(1429)  评论(0编辑  收藏  举报