资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

jquery图片自适应,设置图片自适应

jquery mobile 图片如何自动适应大小?

这位网友你好,你可以设置图片的宽度为100%就可以自适应大小了~

创新互联建站是一家专注于成都做网站、网站设计与策划设计,通榆网站建设哪家好?创新互联建站做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:通榆等地区。通榆做网站价格咨询:18982081108

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

CSS/Jquery图片自适应的几种方式

1,用HTML5技术

2,还是传统的HTML,但是可以做CSS,让图片宽度在电脑端和手机端自适应


本文标题:jquery图片自适应,设置图片自适应
本文地址:http://cdkjz.cn/article/phiijh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220