Use the mouse wheel to zoom in or out the mxGraph drawing Area

Source: Internet
Author: User

// Override the mouse wheel event mxEvent. addMouseWheelListener = function (funct) {}// adds the window for the first loading event. onload = function () {var element = document. getElementById ('graph'); addScrollListener (element, wheelHandle);} function addScrollListener (element, wheelHandle) {if (typeof element! = 'Object') return; if (typeof wheelHandle! = 'Function') return; // monitor the browser 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 is a global variable, an mxGraph instance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.