dojo/mouse

Authors:
Kris Zyp

Project owner:
Kris Zyp

since:
1.7.0

Contents

dojo/mouse is a module that provides extension events for hovering and mouse button utility functions. The module has three properties: enter, leave, and mouseButtons.

Usage

Basic usage requires requirement of the module:

require(["dojo/mouse"], function(mouse){
// Mouse extension events available
});

require(["dojo/mouse"], function(mouse){ // Mouse extension events available });

To gain utility out of the module, you must utilize one of three extension events:

require(["dojo/mouse", "dojo/on", "dojo/dom"], function(mouse, on, dom){
on(dom.byId("someid"), mouse.enter, function(evt){
// handle mouse enter event
});
});

require(["dojo/mouse", "dojo/on", "dojo/dom"], function(mouse, on, dom){ on(dom.byId("someid"), mouse.enter, function(evt){ // handle mouse enter event }); });

enter

The dojo/mouse::enter event is an extension event for being notified of when the mouse cursor hovers over an element. This is based on Internet Explorer's mouseenter event and differs mouseover because it does not bubble (mouseover and mouseout are widely considered to be broken because they do bubble and generate many meaningless events for every time the mouse enters a different element within the target element). To use enter, we can listen for an event like:

require(["dojo/mouse", "dojo/on", "dojo/dom"], function(mouse, on, dom){
on(dom.byId("someid"), mouse.enter, function(evt){
// handle mouse enter event
});
});

require(["dojo/mouse", "dojo/on", "dojo/dom"], function(mouse, on, dom){ on(dom.byId("someid"), mouse.enter, function(evt){ // handle mouse enter event }); });

leave

The dojo/mouse::leave event is an extension event for being notified of when the mouse cursor stops hovering over an element. This is based on Internet Explorer's mouseleave event and again differs mouseout because it does not bubble. To use leave, we can listen for an event like:

require(["dojo/mouse", "dojo/on", "dojo/dom"], function(mouse, on, dom){
on(dom.byId("someid"), mouse.leave, function(evt){
// handle mouse leave event
});
});

require(["dojo/mouse", "dojo/on", "dojo/dom"], function(mouse, on, dom){ on(dom.byId("someid"), mouse.leave, function(evt){ // handle mouse leave event }); });

mouseButtons

The mouseButtons object has the following properties and methods:

  • LEFT - The number corresponding to the "button" property value on the event when the left mouse button is clicked.

  • MIDDLE - The number corresponding to the "button" property value on the event when the middle mouse button is clicked.
  • RIGHT - The number corresponding to the "button" property value on the event when the right mouse button is clicked.
  • isLeft(event) - Indicates if the left mouse button was used in the provided event.
  • isMiddle(event) - Indicates if the middle mouse button was used in the provided event.
  • isRight(event) - Indicates if the right mouse button was used in the provided event.

It is designed to make interpretation of mouse events easier. For example:

require(["dojo/mouse", "dojo/on", "dojo/dom"], function(mouse, on, dom){
on(dom.byId("someid"), "click", function(evt){
if (mouse.isLeft(event)){
// handle mouse left click
}else if (mouse.isRight(event)){
// handle mouse right click
}
});
});

require(["dojo/mouse", "dojo/on", "dojo/dom"], function(mouse, on, dom){ on(dom.byId("someid"), "click", function(evt){ if (mouse.isLeft(event)){ // handle mouse left click }else if (mouse.isRight(event)){ // handle mouse right click } }); });

Examples

RunSourceCollapse

This example applies a CSS class to a node when the mouse hovers over it.

require(["dojo/mouse", "dojo/dom", "dojo/dom-class", "dojo/on", "dojo/domReady!"],
function(mouse, dom, domClass, on){
on(dom.byId("hoverNode"), mouse.enter, function(){
domClass.add("hoverNode", "hoverClass");
}); on(dom.byId("hoverNode"), mouse.leave, function(){
domClass.remove("hoverNode", "hoverClass");
});
});

require(["dojo/mouse", "dojo/dom", "dojo/dom-class", "dojo/on", "dojo/domReady!"], function(mouse, dom, domClass, on){ on(dom.byId("hoverNode"), mouse.enter, function(){ domClass.add("hoverNode", "hoverClass"); }); on(dom.byId("hoverNode"), mouse.leave, function(){ domClass.remove("hoverNode", "hoverClass"); }); });

<div id="hoverNode">Hover Over Me!</div>

<div id="hoverNode">Hover Over Me!</div>

#hoverNode { width: 200px; height: 100px; border: 1px solid black; }
.hoverClass { background-color: red; }

#hoverNode { width: 200px; height: 100px; border: 1px solid black; } .hoverClass { background-color: red; }

See Also

[转]dojo/mouse的更多相关文章

  1. Events with Dojo(翻译)

    In this tutorial, we will be exploring dojo/on and how Dojo makes it easy to connect to DOM events. ...

  2. dojo事件驱动编程之事件绑定

    什么是事件驱动? 事件驱动编程是以事件为第一驱动的编程模型,模块被动等待通知(notification),行为取决于外来的突发事件,是事件驱动的,符合事件驱动式编程(Event-Driven Prog ...

  3. DOJO 八 event dojo/on

    官网教程:Events with Dojo在元素上绑定events,需要引用包dojo/on,通过on方法来实现. <button id="myButton">Clic ...

  4. Dojo实现Tabs页报错(三)

    用Dojo实现tab页的过程中,没有引用“on.js”,但是firebug调试时一直提示如下错误: on.js源码如下: define(["./has!dom-addeventlistene ...

  5. Dojo API中文 Dojo内容模块概览,初学者

    官网:http://dojotoolkit.org/reference-guide/1.10/dojo/index.html#dojo-dojo的翻译 dojo 内容: dojo dojo/dojo ...

  6. Dojo Widget系统(转)

    Dojo 里所有的小部件(Widget)都会直接或间接的继承 dijit._Widget / dijit._WidgetBase dijit._Widget 是 dojo 1.6 和 1.6之前的版本 ...

  7. Dojo Style Guide

    Contents: General Quick Reference Naming Conventions Specific Naming Conventions Files Variables Lay ...

  8. Dojo Javascript 编程规范(转)

    前言 相当不错的 Javascript 编程风格规范,建议大家采用此规范编写 Javascript.原文链接: http://dojotoolkit.org/developer/StyleGuide ...

  9. dojo框架笔记

    一.模块定义 1.定义只含值对,没有任何依赖的模块(moudle1.js) define({ color: "black", size: "unisize" } ...

随机推荐

  1. C++定义一个简单的Computer类

    /*定义一个简单的Computer类 有数据成员芯片(cpu).内存(ram).光驱(cdrom)等等, 有两个公有成员函数run.stop.cpu为CPU类的一个对象, ram为RAM类的一个对象, ...

  2. BZOJ2844: albus就是要第一个出场(线性基)

    Time Limit: 6 Sec  Memory Limit: 128 MBSubmit: 2054  Solved: 850[Submit][Status][Discuss] Descriptio ...

  3. SpringBoot配置redis和分布式session-redis

    springboot项目 和传统项目 配置redis的区别,更加简单方便,在分布式系统中,解决sesssion共享问题,可以用spring session redis. 1.pom.xml <d ...

  4. 全盘解决eclipse之maven项目报错

    每次新建maven的web(war包方式)项目时都会报错而且都要手动改,很麻烦 解决:(注意里面的jdk版本换成自己的) 改变maven配置文件   settings.xml 在文件的<prof ...

  5. Windows之cmd指令

    gpedit.msc-----本地计算机策略sndrec32-------录音机 Nslookup-------IP地址侦测器 explorer-------打开资源管理器 logoff------- ...

  6. 【bind服务简单发布及优化部署】

    主DNS 1:安装bind服务包 2:vim  /etc/named.conf区域解析控制文件 3:vim /etc/named.rfc1912.zones解析方向文件 4:vim var/named ...

  7. (转)程序员新人怎样在复杂代码中找 bug?

    我曾经做了两年大型软件的维护工作,那个项目有10多年了,大约3000万行以上的代码,参与过开发的有数千人,代码checkout出来有大约5个GB,而且bug特别多,open的有上千,即使最高优先级的s ...

  8. QQ群认证 人数再度扩容 权限随之升级

    群排名,得资源得天;之于排名,群容量有杠杆意义. 而今,流量分散,打法完全无法集中,全平台战略,越发凸显.QQ群,已是必争之地. 去年,Q群霸屏春天,一切那么顺其自然;而今,除了拼资源,还是拼资源.除 ...

  9. tp5 数据库信息导出到excel(带图片)

    function excel_down(){ //导入谁就去查谁 $data=Db::name('order_xueyou')->select(); // 导出Exl // import(&qu ...

  10. 勾股数--Python

    勾股数:勾股数又名毕氏三元数 .勾股数就是可以构成一个直角三角形三边的一组正整数.勾股定理:直角三角形两条直角边a.b的平方和等于斜边c的平方(a²+b²=c²) 要求:输出1000以内的勾股数 fr ...