jquery图片大小,jquery获取图片宽度-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

jquery图片大小,jquery获取图片宽度

jquery 如何让图片自适应大小

script type="text/javascript" src="js/jquery.min.js"/script

创新互联专注于鹿寨企业网站建设,成都响应式网站建设公司,商城网站定制开发。鹿寨网站建设公司,为鹿寨等地区提供建站服务。全流程定制设计,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

script type="text/javascript"

jQuery.fn.LoadImage=function(scaling,width,height,loadpic){

if(loadpic==null)loadpic="../img/loading.gif";

return this.each(function(){

var t=$(this);

var src=$(this).attr("src")

var img=new Image();

img.src=src;

//自动缩放图片

var autoScaling=function(){

if(scaling){

if(img.width0 img.height0){

if(img.width/img.height=width/height){

if(img.widthwidth){

t.width(width);

t.height((img.height*width)/img.width);

}else{

t.width(img.width);

t.height(img.height);

}

}

else{

if(img.heightheight){

t.height(height);

t.width((img.width*height)/img.height);

}else{

t.width(img.width);

t.height(img.height);

}

}

}

}

}

//处理ff下会自动读取缓存图片

if(img.complete){

autoScaling();

return;

}

$(this).attr("src","");

var loading=$("img alt=\"加载中...\" title=\"图片加载中...\" src=\""+loadpic+"\" /");

t.hide();

t.after(loading);

$(img).load(function(){

autoScaling();

loading.remove();

t.attr("src",this.src);

t.show();

});

} );

}

/script

div id="content"img src="img/20120518073933709.jpg"//div

script type="text/javascript"

!--

$(window).load(function(){

$('#content img').LoadImage(true, 600,500,'img/loading.gif');

});

//--

/script

jquery怎么设置图片的大小

$(document).ready(function() { $('.post img').each(function() { var maxWidth = 100; // 图片最大宽度 var maxHeight = 100; // 图片最大高度 var ratio = 0; // 缩放比例 var width = $(this).width(); // 图片实际宽度 var height = $(this).height(); // 图片实际高度 // 检查图片是否超宽 if(width maxWidth){ ratio = maxWidth / width; // 计算缩放比例 $(this).css("width", maxWidth); // 设定实际显示宽度 height = height * ratio; // 计算等比例缩放后的高度 $(this).css("height", height); // 设定等比例缩放后的高度 } // 检查图片是否超高 if(height maxHeight){ ratio = maxHeight / height; // 计算缩放比例 $(this).css("height", maxHeight); // 设定实际显示高度 width = width * ratio; // 计算等比例缩放后的高度 $(this).css("width", width * ratio); // 设定等比例缩放后的高度 } }); });

jquery怎么压缩图片质量与大小?

jquery不能更改图片的体积。你可以试试服务端语言,如java php nodejs之类的

jquery怎样限制上传图片的大小和像素宽高,分辨率

script type="text/javascript" 

function validate_img(a){

var file = a.value;

if(!/.(gif|jpg|jpeg|png|GIF|JPG|png)$/.test(file)){

alert("图片类型必须是.gif,jpeg,jpg,png中的一种");

return false;

}else{

var image = new Image();

image.src = file;

var height = image.height;

var width = image.width;

var filesize = image.filesize;

  alert(height+"x.."+filesize);

if(width80  height80  filesize102400){

alert('请上传80*80像素 或者大小小于100k的图片');

  return false;

}

}

alert("图片通过");

}

/script 

图像:input type="file" name="uploadImg" onchange="Javascript:validate_img(this);" size="12"/

测试的时候放服务器上测试,本地不行的哈~


本文标题:jquery图片大小,jquery获取图片宽度
文章源于:http://kswsj.cn/article/dscgpdd.html

其他资讯