智睿软件_技术交流论坛综合站长Web页面设计 → [推荐]js图片放大缩小代码


  共有13848人关注过本帖树形打印

主题:[推荐]js图片放大缩小代码

帅哥哟,离线,有人找我吗?
zhirui
  1楼 个性首页 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:520 积分:8740 威望:0 精华:5 注册:2009-07-07
[推荐]js图片放大缩小代码  发帖心情 Post By:2014-04-09 16:47:44

 
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" c    />
<meta name="auther" c    />
<title>图片放大缩小</title>
<script type="text/javascript">
// 放大缩小控制
var PhotoSize = {
zoom: 0, // 缩放率
count: 0, // 缩放次数
cpu: 0, // 当前缩放倍数值
elem: "", // 图片节点
photoWidth: 0, // 图片初始宽度记录
photoHeight: 0, // 图片初始高度记录
init: function(){
this.elem = document.getElementById("focusphoto");
this.photoWidth = this.elem.scrollWidth;
this.photoHeight = this.elem.scrollHeight;
this.zoom = 1.2; // 设置基本参数
this.count = 0;
this.cpu = 1;
},
action: function(x){
if(x === 0){
this.cpu = 1;
this.count = 0;
}else{
this.count += x; // 添加记录
this.cpu = Math.pow(this.zoom, this.count); // 任意次幂运算
};
this.elem.style.width = this.photoWidth * this.cpu +"px";
this.elem.style.height = this.photoHeight * this.cpu +"px";
}
};
// 启动放大缩小效果 用onload方式加载,防止第一次点击获取不到图片的宽高
window.onload = function(){PhotoSize.init()};
</script>
</head>
<body>
<input type="button" value="放大" > <input type="button" value="缩小" > <input type="button" value="还原大小" > <input type="button" value="查看当前倍数" ><br>
<img id="focusphoto" src="/docimg/201111/24/1354009769.jpg">
</body>
</html>

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:放大放小代码.rar


国际域名60元,空间八折优惠,企业的顶级合作伙伴 支持(3中立(0反对(0回到顶部