首页 > Web开发 > 详细

jQuery 图片等比缩放

时间:2016-06-27 15:39:50      阅读:323      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!