图片覆盖整个网页php,网页图片自适应处理方法

本文总结了三种网页图片自适应处理方法,具体解决办法如下:

第一种方法:

01.gif

function drawImage(ImgD,ImgDWidth,ImgDHeight){

var image=new Image();

image.src=ImgD.src;

if(image.width/image.height>=ImgDWidth/ImgDHeight){

if(image.width>ImgDWidth){

ImgD.width=ImgDWidth;

ImgD.height=(image.height*ImgDWidth)/image.width;

}

else{

ImgD.width=image.width;

ImgD.height=image.height;

}

}

else{

if(image.height>ImgDHeight){

ImgD.width=(image.width*ImgDHeight)/image.height;

ImgD.height=ImgDHeight;

}

else{

ImgD.width=image.width;

ImgD.height=image.height;

}

}

}

第二种方法:

2011618143434260.jpg

//图片自动调整的模式,1为按比例调整 ,2 按大小调整。

var resizemode=1

function imgresize(o){

if(resizemode==2 || o.onmousewheel){

if(o.width > 500 ){

o.style.width='500px';

}

if(o.height > 800){

o.style.height='800px';

}

}else{

var parentNode=o.parentNode.parentNode;

if(parentNode){

if(o.offsetWidth>=parentNode.offsetWidth){

o.style.width='98%';

}

}else{

var parentNode=o.parentNode

if(parentNode){

if(o.offsetWidth>=parentNode.offsetWidth){

o.style.width='98%';

}

}

}

}

}

第三种办法(Jquery解决的),关键代码如下:

$('#ac_content img').each(function(){

appropriate_width=300;

if($(this).width()>appropriate_width){

$(this).css({'width':appropriate_width+'px','height':$(this).height()*appropriate_width/$(this).width()+'px'});

$(this).attr('title','点击查看大图片');

$(this).bind({

click:function(){

window.open($(this).attr('src'));

}

});

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值