深圳网站建设公司,网商在线LOGO

您的位置:首页 > 新闻

网页中图片大小自动调整四种方法
新闻 2024-9-21编辑:深圳网站建设阅读(标签: 图片

网页中图片大小自动调整四种方法

1.鼠标滚动图片大小调整

2.图片自动缩小到固定大小
3.滚轮图片缩放的代码

4.内容中的图片大小不撑破网页

鼠标滚动图片大小调整

<body>
<script LANGUAGE="JAVASCRIPT">
function bbimg(o){
   var zoom=parseInt(o.style.zoom, 10)||100;

zoom+=event.wheelDelta/12;

if (zoom>0)

 o.style.zoom=zoom+'%';


   return false;
}
</script> 
<img src="123.jpg" onload="javascript:if(this.width>screen.width-screen.width/2) this.style.width=screen.width-screen.width/2" onmousewheel="return bbimg(this)" > 
</body>

图片自动缩小到固定大小

<body onload="DrawImage(theimg)">
<script language="JavaScript">
<!--
//图片按【àn】比例缩放
var flag=false;
function DrawImage(ImgD){
  var image=new Image();
  var iwidth = 320;  //定义允许图【tú】片宽度【dù】
  var iheight = 180;  //定【dìng】义允许图【tú】片高度
  image.src=ImgD.src;
  if(image.width>0 && image.height>0){
   flag=true;
   if(image.width/image.height>= iwidth/iheight){
    if(image.width>iwidth){  
    ImgD.width=iwidth;
    ImgD.height=(image.height*iwidth)/image.width;
    }else{
    ImgD.width=image.width;  
    ImgD.height=image.height;
    }
    ImgD.alt=image.width+"×"+image.height;
    }
   else{
    if(image.height>iheight){  
    ImgD.height=iheight;
    ImgD.width=(image.width*iheight)/image.height;     
    }else{
    ImgD.width=image.width;  
    ImgD.height=image.height;
    }
    ImgD.alt=image.width+"×"+image.height;
    }
   }
} 
//-->
</script>
<img src="123.jpg" width="1024" height="768" name="theimg">
</body> 

滚轮图片缩放的代码

<script language="javascript">
var count = 10;
function resizeimg(oImage)
{ 
count = Counting(count);
Resize(oImage,count);
return false;
}
function Counting(newzoom){ 
if (event.wheelDelta >= 120)
newzoom++;
else if (event.wheelDelta <= -120)
newzoom--;
if (newzoom<2) newzoom=2; ////只【zhī】允许缩小到20%
if (newzoom>50) newzoom=50; ////只允【yǔn】许放大到【dào】500%
return newzoom; 
}
function Resize(oImage,newzoom){ 
oImage.style.zoom = newzoom + '0%'; 
count=newzoom;
}
</script>
然后在<img src="">中加入
onDblClick="return Resize(this,10);return false;" 
onmousewheel="return resizeimg(this)"

内容中的图片大小不撑破网页

img {border: 1px solid #ddd; padding: 2px;
max-width:100%; max-height:auto;}


企业网站定制

企业网站定制 根据企业需求,量身定制设计

企业网站定制:2800元起
添加微信 请说明来意
联系我们
站内搜索

24小时服务热线 0755-29765948
  • 地址:深圳市罗湖区人民北路2033号206
  • 电【diàn】话【huà】:0755-29765948 传真:82256610
  • 手机:13714666846 18948334877
  • 邮箱:gong@city96.com 164761418@qq.com
  • 粤ICP备14049207号
创意化数字品牌整合网络营销
营销网站让你坐等商机坐佣客户,Rss

版权所有:深圳市网商在线科技有限公司

友情链接: