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

摘要:
1.鼠标滚动图像大小调整<body><scriptLANGUAGE=“JAVASCRIPT”>函数bbimg(o){varzoom=parseInt(o.style.szoom,10)||100;zoom+=event.wheelDelta/12;if(zoom˃0)o.style.s缩放=缩放+‘%’;returnfalse;}˂imgsrc=“http://t
1.鼠标滚动图片大小调整

<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="http://t.zoukankan.com/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>

2.图片自动缩小到固定大小

<body onload="DrawImage(theimg)">
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
  var image=new Image();
  var iwidth = 320;  //定义允许图片宽度
  var iheight = 180;  //定义允许图片高度
  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="http://t.zoukankan.com/123.jpg" width="1024" height="768" name="theimg">
</body> 


3.滚轮图片缩放的代码

<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; ////只允许缩小到20%
if (newzoom>50) newzoom=50; ////只允许放大到500%
return newzoom; 
}
function Resize(oImage,newzoom){ 
oImage.style.zoom = newzoom + '0%'; 
count=newzoom;
}
</script>

然后在<img src="https://tool.4xseo.com/article/176016.html">中加入
onDblClick="return Resize(this,10);return false;" 
onmousewheel="return resizeimg(this)"

免责声明:文章转载自《网页中图片大小自动调整三种方法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SecureCRT上传和下载文件(下载默认目录)Sass中常用的函数下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

MyBatisPlus使用

简介MyBatis Plus是MyBatis的增强工具。基于MyBatis,只进行了增强而不进行更改。它旨在简化开发并提高效率。...

IDEA的设置打不开,点了没反应解决办法

把它去掉用回英文d就可以了。...

vant上传文件到后端

Html代码&lt;Ts代码文件列表=[]/image/[a-zA-z]+/。test(file.file.type)){this.$toast(“请上传图片”);returnfalse;config).then(res=&gt;})。捕获(()=&gt;拒绝)=&gt;ts=“+newDate().getTime()).然后...

js 浏览器窗口 刷新、关闭事件

当前页面不会直接关闭,可以点击确定按钮关闭或刷新,也可以取消关闭或刷新。...

Vant 实现 上拉加载更多

Vant的List组件默认支持瀑布流滚动加载。官方的示例是用定时器模拟的数据。我们在项目实战中,肯定是结合ajax请求处理的。那么我们该如何实现这个效果呢?Vant的List组件使用方法这里就不详细说明了,官方文档已经写的很详细了。直接上项目中的实战代码://itemList换成你自己的数据//没数据时显示˂divclass="no-data"v-if="!...

Nginx实战-后端应用健康检查

utm_source=tuicool&utm_medium=referral公司前一段对业务线上的nginx做了整理,重点就是对nginx上负载均衡器的后端节点做健康检查。比如如果将max_fails设置为0,则代表不对后端服务器进行健康检查,这样还会使fail_timeout参数失效。...