MooTools Custom Events


/ Published in: JavaScript
Save to your folder(s)

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)


Copy this code and paste it in your HTML
  1. /* Example 1: Alt-Click on div#foo */
  2. Element.Events.altClick = {
  3. base: "click",
  4. condition: function(e) {
  5. return e.alt;
  6. }
  7. };
  8. var clicks = 0;
  9. $("foo").addEvent("altClick", function(e) {
  10. clicks++;
  11. this.set("text", clicks);
  12. });
  13.  
  14. /* Example 2: Shift-H Shortcut */
  15. Element.Events.shiftH = {
  16. base: "keypress",
  17. condition: function(e) {
  18. if (e.shift && e.key == "h") { return true; }
  19. }
  20. };
  21. window.addEvent("shiftH", function() {
  22. var div = $("foo");
  23. var opacity = (div.get("opacity") == 0 ? 1 : 0);
  24. div.tween("opacity", opacity);
  25. });

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.