Return to Snippet

Revision: 26338
at April 23, 2010 09:38 by cfleschhut


Initial Code
/* Example 1: Alt-Click on div#foo */
Element.Events.altClick = {
    base: "click",
    condition: function(e) {
        return e.alt;
    }
};
var clicks = 0;
$("foo").addEvent("altClick", function(e) {
    clicks++;
    this.set("text", clicks);
});

/* Example 2: Shift-H Shortcut */
Element.Events.shiftH = {
    base: "keypress",
    condition: function(e) {
        if (e.shift && e.key == "h") { return true; }
    }
};
window.addEvent("shiftH", function() {
    var div = $("foo");
    var opacity = (div.get("opacity") == 0 ? 1 : 0);
    div.tween("opacity", opacity);
});

Initial URL
http://jsfiddle.net/Qp2MM/

Initial Description
via [https://www.packtpub.com/mootools-1-2-beginners-guide/book](https://www.packtpub.com/mootools-1-2-beginners-guide/book) & [http://davidwalsh.name/mootools-custom-event](http://davidwalsh.name/mootools-custom-event)

Initial Title
MooTools Custom Events

Initial Tags
javascript

Initial Language
JavaScript