网页中图片大小自动调整三种方法
2008-07-12 20:46
519 查看
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="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="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="">中加入
onDblClick="return Resize(this,10);return false;"
onmousewheel="return resizeimg(this)"
<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>
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="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="">中加入
onDblClick="return Resize(this,10);return false;"
onmousewheel="return resizeimg(this)"
相关文章推荐
- 网页中图片大小自动调整三种方法
- 网页中图片大小自动调整三种方法
- 网页中图片大小自动调整三种方法
- 小白走一波关于图片调整大小适配网页的基础方法
- 背景图片随网页内容自动调整大小
- CSS控制背景图片随网页或容器自动调整大小
- JS限定手机版中图片大小随分辨率自动调整的方法
- 让 UILabel 根据字体自动调整大小的方法
- JS限定手机版中图片大小随分辨率自动调整
- 新闻内容页面自动调整超宽图片大小
- 三种简单的html网页自动跳转方法
- 据客户端(浏览器中的网页body部分)的大小来动态的调整客户端内显示图像的大小,防止因浏览器的不同导致看见的图片不同
- 网页中如何使超出页面大小的图片自动适合页面宽度?
- 图片自动缩放 图片调整大小
- jQuery实现自动调整字体大小的方法
- img 图片 网页 调整大小 缩放
- 网页中JS函数自动执行常用三种方法
- Android图片大小调整动态实现方法(bitmap)
- 在网页中JS函数自动执行常用三种方法
- 在网页中JS函数自动执行常用三种方法