// 重写鼠标滚轮事件
mxEvent.addMouseWheelListener = function (funct) { } // 添加初次载入事件
window.onload = function () {
var element= document.getElementById('graph');
addScrollListener(element, wheelHandle);
} function addScrollListener(element, wheelHandle) {
if (typeof element != 'object') return;
if (typeof wheelHandle != 'function') return; // 监測浏览器
if (typeof arguments.callee.browser == 'undefined') {
var user = navigator.userAgent;
var b = {};
b.opera = user.indexOf("Opera") > -1 && typeof window.opera == "object";
b.khtml = (user.indexOf("KHTML") > -1 || user.indexOf("AppleWebKit") > -1 || user.indexOf("Konqueror") > -1) && !b.opera;
b.ie = user.indexOf("MSIE") > -1 && !b.opera;
b.gecko = user.indexOf("Gecko") > -1 && !b.khtml;
arguments.callee.browser = b;
}
if (element == window)
element = document;
if (arguments.callee.browser.ie)
element.attachEvent('onmousewheel', wheelHandle);
else
element.addEventListener(arguments.callee.browser.gecko ? 'DOMMouseScroll' : 'mousewheel', wheelHandle, false);
} function wheelHandle(e) {
var upcheck; if (e.wheelDelta) {
upcheck = e.wheelDelta > 0 ? 1 : 0;
} else {
upcheck = e.detail < 0 ? 1 : 0;
}
if (upcheck) {
myGraph.zoomIn();
}
else {
myGraph.zoomOut();
} if (window.event) {
e.returnValue = false;
window.event.cancelBubble = true;
} else {
e.preventDefault();
e.stopPropagation();
}
}

PS:myGraph是一个全局变量,mxGraph的实例

05-08 08:00