手机拍照或者选择相册里的图片,通常不是正方形的,而通过数据库查询出来的图片需要显示成正方形,我目前的出来是截取中间的部分
function imgLoad(id) {
var node = $('#' + id);
var height = node.height();
var width = node.width();
$('#div' + id).height(viewModel.c_width());
$('#div' + id).width(viewModel.c_width());
// console.log(height +' :'+width)
if (height > width) { node.width(viewModel.c_width());
// node.height(viewModel.c_width());
node.css('margin-top', -(viewModel.c_width() * height / width - viewModel.c_width()) / 2);
} else {
$('#' + id).width(viewModel.c_width() * viewModel.c_width() / height);
node.css('margin-left', -(viewModel.c_width() * width / height - viewModel.c_width()) / 2);
}
}这里是获取到的长方形的图片,截取中间的部分,还有没有什么好的方法???
暮色呼如
相关分类