鼠标滚轮控制图片大小
2007-08-01 16:13
330 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>滚动效果</title>
<script type="text/javascript">
(function (bool) {
//兼容FF一些方法
window.FF = bool;
if (bool) {
window.attachEvent = document.attachEvent = window.HTMLElement.prototype.attachEvent = function (property, func, bool) {
//兼容attachEvent方法
return this.addEventListener(property.replace(/^on/, ""), func, bool || false);
};
window.__defineGetter__("event", function () {
//兼容Event对象
var o = arguments.callee;
do {
if (o.arguments[0] instanceof Event) return o.arguments[0];
} while (o = o.caller);
return null;
});
Event.prototype.__defineGetter__("srcElement", function () {
//兼容Event.srcElement对象
return this.target;
});
MouseEvent.prototype.__defineGetter__("wheelDelta", function () {
//返回鼠标滚轮状态
return this.detail * -1;
});
}
})(/Firefox/.test(window.navigator.userAgent));
var Class = {
//创建类
create : function () {
return function () {
this.initialize.apply(this, arguments);
};
}
};
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
var wheel = Class.create();
wheel.prototype = {
//鼠标滚动图片类
initialize : function (obj, num) {
//初始化参数
var wc = this;
(wc.img = obj).attachEvent(!window.FF ? "onmousewheel" : "DOMMouseScroll", function () {
wc.move(num * (window.event.wheelDelta > 0 ? -1 : 1));
});
wc.item = [
[ obj.offsetWidth, "width", "offsetWidth" ], [ obj.offsetHeight, "height", "offsetHeight" ]
].sort(function (a, b) { return b[0] - a[0]; }); //把高和宽从大到小排序
},
move : function (num) {
//改变值
var wc = this, img = wc.img, a = wc.item;
//大值除以小值在乘以固定值就是比例缩放
img.style[a[0][1]] = Math.max(
img[a[0][2]] + Math.round(a[0][0] / a[1][0] * num), a[0][0]
) + "px";
//小值不用管
img.style[a[1][1]] = Math.max(
img[a[1][2]] + num, a[1][0]
) + "px";
}
};
window.attachEvent("onload", function () {
var wc = new wheel($("div"), 10);
$("a").onclick = function () {
wc.move(50);
};
$("b").onclick = function () {
wc.move(-50);
};
});
</script>
</head>
<body>
<img id="div" height="60" width="280" src="http://hi.csdn.net/images/csdnlogo.gif" alt="" />
<br />
<input id="a" type="button" value="加" /> <input id="b" type="button" value="减" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>滚动效果</title>
<script type="text/javascript">
(function (bool) {
//兼容FF一些方法
window.FF = bool;
if (bool) {
window.attachEvent = document.attachEvent = window.HTMLElement.prototype.attachEvent = function (property, func, bool) {
//兼容attachEvent方法
return this.addEventListener(property.replace(/^on/, ""), func, bool || false);
};
window.__defineGetter__("event", function () {
//兼容Event对象
var o = arguments.callee;
do {
if (o.arguments[0] instanceof Event) return o.arguments[0];
} while (o = o.caller);
return null;
});
Event.prototype.__defineGetter__("srcElement", function () {
//兼容Event.srcElement对象
return this.target;
});
MouseEvent.prototype.__defineGetter__("wheelDelta", function () {
//返回鼠标滚轮状态
return this.detail * -1;
});
}
})(/Firefox/.test(window.navigator.userAgent));
var Class = {
//创建类
create : function () {
return function () {
this.initialize.apply(this, arguments);
};
}
};
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
var wheel = Class.create();
wheel.prototype = {
//鼠标滚动图片类
initialize : function (obj, num) {
//初始化参数
var wc = this;
(wc.img = obj).attachEvent(!window.FF ? "onmousewheel" : "DOMMouseScroll", function () {
wc.move(num * (window.event.wheelDelta > 0 ? -1 : 1));
});
wc.item = [
[ obj.offsetWidth, "width", "offsetWidth" ], [ obj.offsetHeight, "height", "offsetHeight" ]
].sort(function (a, b) { return b[0] - a[0]; }); //把高和宽从大到小排序
},
move : function (num) {
//改变值
var wc = this, img = wc.img, a = wc.item;
//大值除以小值在乘以固定值就是比例缩放
img.style[a[0][1]] = Math.max(
img[a[0][2]] + Math.round(a[0][0] / a[1][0] * num), a[0][0]
) + "px";
//小值不用管
img.style[a[1][1]] = Math.max(
img[a[1][2]] + num, a[1][0]
) + "px";
}
};
window.attachEvent("onload", function () {
var wc = new wheel($("div"), 10);
$("a").onclick = function () {
wc.move(50);
};
$("b").onclick = function () {
wc.move(-50);
};
});
</script>
</head>
<body>
<img id="div" height="60" width="280" src="http://hi.csdn.net/images/csdnlogo.gif" alt="" />
<br />
<input id="a" type="button" value="加" /> <input id="b" type="button" value="减" />
</body>
</html>
相关文章推荐
- 鼠标滚轮控制图片大小
- c# winform 用鼠标滚轮控制图片大小,获取鼠标中键滚轮事件,MouseWheel事件
- [转]c# winform 用鼠标滚轮控制图片大小,获取鼠标中键滚轮事件,MouseWheel事件
- C#winform用鼠标滚轮控制图片大小,MouseWheel事件
- 学习笔记 鼠标滚轮控制图片大小
- 鼠标滚轮控制图片大小
- 鼠标滚轮控制图片大小,获取滚轮事件
- [网页]鼠标滚轮控制图片大小
- 鼠标滚轮控制图片大小。
- 鼠标滚轮控制图片大小
- jQuery实现的鼠标滚轮控制图片缩放功能实例
- 鼠标滚轮控制图片缩放
- js实现鼠标滚轮控制图片缩放效果的方法
- Pycharm中用鼠标滚轮控制字体大小
- 鼠标控制图片大小
- 图片按比例缩放,鼠标滚轮调整大小
- 用鼠标滑轮控制图片大小的显示
- Pycharm用鼠标滚轮控制字体大小
- 滚轮控制图片大小
- js实现鼠标滚轮控制图片缩放效果的方法