All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
如何在C#中播放AVI短片并使背景透明_[Asp.Net教程]
数据库的备份与还原_[SQL,Server教程]
三步堵死SQL注入漏洞_[SQL,Server教程]
有用的SQL语句(删除重复记录,收缩日志)_[SQL,Server教程]
使用AJAX技术打造博客无刷新搜索引擎_[AJAX教程]
ASP.NET,2.0主题和皮肤实现网站美化_[Asp.Net教程]
深入ASP.NET数据绑定(中)——数据双向绑定机理_[Asp.Net教程]
在asp.net,页面中加入skype功能_.net资料_编程技术
全面接触SQL语法(6)_mssql学习_编程技术
asp.net2.0网站基础之程序运行
Reading number is top 10 pictures
Terrorist smile the largest human history an explosion1
美女挤公交
So beauty, will let you spray blood8
So beauty, will let you spray blood2
史上最大的哺乳动物迁移
Magnificent cloud2
怀春少女-石一伊
穷哥们向美女求婚攻略
猫眯也疯狂
关于海盗的研究
Download software ranking
Unix video tutorial9
C#编程思想
C++编程教程第三版
打鸟视频
Unix video tutorial5
VC++6.0培训教程
天龙八部最新服务端
Unix video tutorial13
Such love down(擒爱记)
C#程序员参考手册
delv published in(发表于) 2013/12/31 6:34:56 Edit(编辑)
javascript实现网页图片等比例缩放_JavaScript技术_编程技术

javascript实现网页图片等比例缩放_JavaScript技术_编程技术

javascript实现网页图片等比例缩放_JavaScript技术_编程技术-你的首页-uuhomepage.com

参考了一些代码,自己写了个图片缩放的脚本,可以点击放大,同时用鼠标滑轮自由缩放.


//图片按比例缩放,可输入参数设定初始大小
function resizeimg(ImgD,iwidth,iheight) {
var image=new Image();
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(this.src);} //点击打开大图片
    if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器,如果是IE
      ImgD.title = "请使用鼠标滚轮缩放图片,点击图片可在新窗口打开";
      ImgD.onmousewheel = function img_zoom() //滚轮缩放
      {
          var zoom = parseInt(this.style.zoom, 10) || 100;
          zoom += event.wheelDelta / 12;
          if (zoom> 0) this.style.zoom = zoom + "%";
          return false;
      }
    } else { //如果不是IE
        ImgD.title = "点击图片可在新窗口打开";
       }
}
}


具体实现代码如下:



可能必较多,如果有更好的代码,欢迎指教!





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.