基本上我想做的是当我向上滚动时,放大我的表格,使其变大,当我向下滚动时,缩小表格,使其变小。
这是js
var mainGridW = $("#mainGrid").width();
var mainGridH = $("#mainGrid").height();
function setupMouseWheel(){
if (zoomContainer.addEventListener) {
zoomContainer.addEventListener('DOMMouseScroll', onMouseWheelSpin, false);
zoomContainer.addEventListener('mousewheel', onMouseWheelSpin, false); // Chrome
}else{
zoomContainer.onmousewheel= onMouseWheelSpin;
}
}
function onMouseWheelSpin(event) {
var nDelta = 0;
if (!event) { event = window.event; }
// cross-bowser handling of eventdata to boil-down delta (+1 or -1)
if ( event.wheelDelta ) { // IE and Opera
nDelta= event.wheelDelta;
if ( window.opera ) { // Opera has the values reversed
nDelta= -nDelta;
}
}
else if (event.detail) { // Mozilla FireFox
nDelta= -event.detail;
}
if (nDelta > 0) {
HandleMouseSpin( 1, event.clientX, event.clientY );
}
if (nDelta < 0) {
HandleMouseSpin( -1, event.clientX, event.clientY );
}
if ( event.preventDefault ) { // Mozilla FireFox
event.preventDefault();
}
event.returnValue = false; // cancel default action
}
function HandleMouseSpin(delta, x, y) {
if (delta < 0){
mainGridW = mainGridW/1.10;
mainGridH = mainGridH/1.10;
$("#mainGrid").width(mainGridW);
$("#mainGrid").height(mainGridH);
}
if(delta > 0){
mainGridW = mainGridW*1.10;
mainGridH = mainGridH*1.10;
$("#mainGrid").width(mainGridW);
$("#mainGrid").height(mainGridH);
}
}
这是html
<body onload="setupMouseWheel();">
<div id="zoomContainer">
<table id="mainGrid" height="100%" width="100%" cellpadding="0" cellspacing="0"></table>
</div>
</body>
这一切都有效,除了一个问题......在Firefox中,它工作之前有一个滞后。当我尝试滚动时,它会说“没有响应”几秒钟,然后在它再次开始响应后它会起作用,但速度很慢。有任何想法吗?提前致谢。