|

楼主 |
发表于 2017-6-20 21:45:40
|
显示全部楼层
网上找到方法 求问 如果是多张图片 在 怎么用for循环处理方法怎么处理哈 麻烦了
Model.prototype.modelLoad = function(event){
var data= this.comp('data1')
var image =data.val('image1')
var src = null;
var t =this.getElementByXid('image3');
function imgLoad(img, callback) {
var timer = setInterval(function() {
if (img.complete) {
callback(img)
clearInterval(timer)
}
}, 50)
}
imgLoad(t, function() {
var width = $(t).width();////得到图片的宽度
var height = $(t).height();//得到图片的高度
var Maxwidth = $(window).width();//获得最大宽度
var Maxheight = $(window).height();///获得最大高度
var margnheight;
var newheight;
if (width >= Maxwidth){
$(t).css("width", Maxwidth);
newheight = height / (width / Maxwidth);
$(t).css("height", newheight);
if(newheight<=Maxheight){
margnheight = (Maxheight - newheight) / 2;
$(t).css("margin-top", margnheight);
}
}else{
if(height<=Maxheight){
margnheight = (Maxheight - height) / 2;
$(t).css("margin-top", margnheight);
}}
})
} |
|