首页  ·  知识 ·  前端
让图片排列的更加整齐:列表图片的排列与自动缩放
hankx  http://hi.baidu.com/hankx/  综合  编辑:dezai  图片来源:网络
图片排列时如果图片的大小不一,怎么让图片排列整齐呢,下面我们来试试: scripttype="text/javascript""

图片排列时如果图片的大小不一,怎么让图片排列整齐呢,下面我们来试试:

http://jquery.com/src/jquery-svn.js">>

 a{font-size:12px;color:#333333;}
 .ImageList{float:left;width:400px;}
 /*一行四个*/
 .ImageList li{float:left;width:90px;text-align:center;margin:3px;border:solid 1px #ebebeb;background:#f7f7f7;padding:5px;}
 /*图片显示区域的大小,固定一下,以便文字对其*/
 .ImageList li .Image{height:60px;width:80px;display:block;border:0px;}
 /*
 使用ul li我不知道如何让图片居中,表格倒是可以,有朋友知道告诉我一声
 */


//这里用到jQuery,写这个是向大家介绍一下jQuery的一个简单用法
//jQuery可以去官方网站下载最新的版本:
http://www.jquery.org
//不用的话可以直接循环,一样可以达到效果,但是麻烦的多
$(document).ready(function(){
 $(".ImageList").find("img").each(
  function(){
   ShowImage(this,80,60);
  }
 );
});

//图片缩放
function ShowImage(ImgD,proMaxWidth,proMaxHeight){
    var image=new Image(); 
    image.src=ImgD.src;
 
    if(image.width>0 && image.height>0){ 
  var rate = (proMaxWidth/image.width < proMaxHeight/image.height)?proMaxWidth/image.width:proMaxHeight/image.height;
  
  if(rate <= 1){   
   ImgD.style.width = image.width*rate;
   ImgD.style.height =image.height*rate;
  }
  else {
            ImgD.style.width = image.width;
            ImgD.style.height =image.height;
        }
    } 
}


 

  • 图片标题

  •  
  • 图片标题

  •  
  • 图片标题

  •  
  • 图片标题

  •  
  • 图片标题

  •  
  •  href="#" class="Text">图片标题

  •  
  • 图片标题

  •  
  • 图片标题


  • 本文作者:hankx 来源:http://hi.baidu.com/hankx/
    CIO之家 www.ciozj.com 微信公众号:imciow
        >>频道首页  >>网站首页   纠错  >>投诉
    版权声明:CIO之家尊重行业规范,每篇文章都注明有明确的作者和来源;CIO之家的原创文章,请转载时务必注明文章作者和来源;
    延伸阅读