This code was originally copied from
Mouse wheel programming in JavaScript [adomas.org]. I replaced about 5 lines of code to get the mousewheel controlling the zoom feature in the
makeZoom.svg [dzone.com] file.
1
2 /** This is high-level function; REPLACE IT WITH YOUR CODE.
3 * It must react to delta being more/less than zero.
4 */
5 function zoomInOut(delta) {
6 if (delta >= 0)
7 zoomIn()
8 else
9 zoomOut()
10 }
11
12 function wheel(event){
13 var delta = 0;
14 if (!event) event = window.event;
15 if (event.wheelDelta) {
16 delta = event.wheelDelta/120;
17 if (window.opera) delta = -delta;
18 } else if (event.detail) {
19 delta = -event.detail/3;
20 }
21 if (delta)
22 zoomInOut(delta);
23 if (event.preventDefault)
24 event.preventDefault();
25 event.returnValue = false;
26 }
27
28 /* Initialization code. */
29 if (window.addEventListener)
30 window.addEventListener('DOMMouseScroll', wheel, false);
31 window.onmousewheel = document.onmousewheel = wheel;