码迷,mamicode.com
首页 > Web开发 > 详细

jQuery 图片等比缩放

时间:2016-06-27 15:40:28      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:

$(function(){

$(‘.img-box img‘).load(function(){
var w = $(this).width();
var h =$(this).height();
if (w < h){
$(this).css(‘height‘,‘100%‘);
var boxw =$(‘.img-box ‘).width();
var $margin = $(‘.img-box ‘).width() - $(this).width();
$(this).css(‘margin-left‘,$margin / 2);
}
else if(h < w){
$(this).css(‘width‘,‘100%‘);
var boxh =$(‘.img-box ‘).height();
var $margin = $(‘.img-box ‘).height() - $(this).height();
$(this).css(‘margin-top‘,$margin / 2);
}
else {
$(this).css(‘width‘,‘100%‘).css(‘height‘,‘100%‘);
}

});
});

jQuery 图片等比缩放

标签:

原文地址:http://www.cnblogs.com/jinsuo/p/5620127.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!