$.fn.DrawImage = function(options) {
return this.each(function(index) {
var $this = jQuery(this);
var opts = jQuery.extend({
width:150,
height:150
}, options || {}
);
var flag=false;
if($this.width()>0 && $this.height()>0){
flag=true;
if($this.width()/$this.height()>= opts.width/opts.height){
if($this.width()>opts.width){
$this.width(opts.width);
$this.height(($this.height()*opts.width)/$this.width());
}
}else{
if($this.height()>opts.height){
$this.height(opts.height);
$this.width(($this.width()*opts.height)/$this.height());
}
}
$this.css("display","inline");
}
});
};
保存以上代码为 DrawImage.js需另外引用jquery.js
用法:
$(document).ready(function(){
$("img").DrawImage({width: 270, height: 270});
});
return this.each(function(index) {
var $this = jQuery(this);
var opts = jQuery.extend({
width:150,
height:150
}, options || {}
);
var flag=false;
if($this.width()>0 && $this.height()>0){
flag=true;
if($this.width()/$this.height()>= opts.width/opts.height){
if($this.width()>opts.width){
$this.width(opts.width);
$this.height(($this.height()*opts.width)/$this.width());
}
}else{
if($this.height()>opts.height){
$this.height(opts.height);
$this.width(($this.width()*opts.height)/$this.height());
}
}
$this.css("display","inline");
}
});
};
保存以上代码为 DrawImage.js需另外引用jquery.js
用法:
$(document).ready(function(){
$("img").DrawImage({width: 270, height: 270});
});