.NEt专家博客!
【凌风雨寒】asp.net:图片按比例缩放,可输入参数设定初始大小
上一篇 /
下一篇 2008-07-22 13:56:15
/ 个人分类:WEB开发
<scriptlanguage="javascript">//图片按比例缩放,可输入参数设定初始大小functionresizeimg(ImgD,iwidth,iheight) {varimage=newImage();
image.src=ImgD.src;if(image.width>0 && image.height>0){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;
}
ImgD.style.cursor="pointer";//改变鼠标指针 ImgD.onclick =function() {window.open(ImgD.src);}//点击打开大图片 if(navigator.userAgent.toLowerCase().indexOf("ie") > -1) {//判断浏览器,如果是IE ImgD.title ="请使用鼠标滚轮缩放图片,点击图片可在新窗口打开";
ImgD.onmousewheel =functionimg_zoom()//滚轮缩放 {
varzoom = parseInt(this.style.zoom, 10) || 100;
zoom +=event.wheelDelta / 12;
if(zoom> 0) this.style.zoom = zoom +"%";
returnfalse;
}
}else{//如果不是IE ImgD.title ="点击图片可在新窗口打开";
}
}
}</script>具体实现代码如下:<imgsrc="http://www.chenjiliang.com/Article/ArticleImage/100/2176/SideFilter9.jpg"onload="javascript.:resizeimg(this,100,200)">
相关阅读:
- 【永春】Asp.Net中虚拟文件系统的使用 (iDotNetSpace, 2008-7-21)
- 【叶帆】.Net Micro Framework研究—FAT文件系统实现探索 (iDotNetSpace, 2008-7-21)
- 【包建强】ASP.NET底层机制 HttpHandler (iDotNetSpace, 2008-7-21)
- 【搞IT的狐狸】ASP.Net动态使用CSS (iDotNetSpace, 2008-7-21)
- 【Q.Lee.lulu】ASP.NET MVC: 修改ViewLocator来动态切换模板 (iDotNetSpace, 2008-7-22)
- 【Q.Lee.lulu 】ASP.NET MVC : 实现我们自己的视图引擎 (iDotNetSpace, 2008-7-22)
- 【涵舍愚人】.NET 框架与架构模式和设计模式详解系列之二:System.dll的功能 (iDotNetSpace, 2008-7-22)
- 【涵舍愚人】.NET 框架与架构模式和设计模式详解系列之三:System.IO (iDotNetSpace, 2008-7-22)
- 【重典】Asp.net MVC Preview 4 中使用RenderComponent (iDotNetSpace, 2008-7-22)
- 【凌风雨寒】解析Asp.net中资源本地化的实现 (iDotNetSpace, 2008-7-22)
导入论坛
引用链接
收藏
分享给好友
推荐到圈子
管理
举报
TAG:
微软