dojo/mouse鼠标

dojo/mouse提供了鼠标事件中需要的属性和方法。

简介:通常用法为:在鼠标事件(onMouseDown(event))中,通过dojo/mouse判断鼠标左键点击、右键点击、中点击还是滚轮滑动。

属性:

enter:鼠标经过(hovers over)

leave:鼠标离开(stop hovers over)

方法:

isLeft(event):鼠标是否左键点击

isMiddle(event):鼠标是否右键点击

isRight(event):鼠标是否中轮点击

wheel(node, listener):鼠标滚轮滑动

实例代码如下(dojo配置和引用代码省略):

 <!DOCTYPE html>
<html >
<head>

<style type="text/css">
@import url("http://localhost/arcgis_js_api/library/3.12/3.12/dijit/themes/claro/claro.css");
</style>
<script type="text/javascript">
var dojoConfig = {
isDebug: true, // 调试
async: true,
parseOnLoad: false
};
</script>
<script type="text/javascript" src="http://localhost/arcgis_js_api/library/3.12/3.12/init.js"></script>

<script> require([ "dojo/ready", "dojo/mouse", "dojo/on", "dojo/dom", "dojox/image/LightboxNano", "dijit/layout/ContentPane", "dijit/form/Button", "dojo/domReady!" ], function (ready,mouse,on,dom,LightboxNano,ContentPane,Button) {var btn = new Button({ label:"Button", onMouseDown:function(event){ alert("onClick"); if(mouse.isLeft(event)){ alert("leftClick"); }else if(mouse.isMiddle(event)){ alert("MiddleClick"); }else if(mouse.isRight(event)){ alert("RightClick"); }else if(mouse.isMiddle(event)){ alert("leftClick"); } } },"btn"); on(dom.byId(btn),mouse.enter,function(){ mouse.wheel(dom.byId(btn),function(e){ alert(e.wheelDelta); }) });
        });
</script>
</head>
<body class="claro">
<div id="btn"></div>
</body>
</html>
 

 

你可能感兴趣的:(dojo)