• Register
  • Log In
  • Home
  • Quick Start
    • Configurator
    • Download YUI 3
  • Documentation
    • User Guides
    • Examples
    • API Docs
    • Environments
    • Tutorials
  • Community
    • Gallery
    • Blog
    • Forums
    • YUI Theater
    • Calendar
  • Contribute
    • YUI on GitHub »
    • File a Ticket
    • View Tickets
    • Dashboard
  • Other Projects
    • Shifter »
    • Yogi »
    • YUI 2
    • YUI Doc »
    • YUI Test
    • YUI Website
    • YUI Compressor »
    • YUI Builder »
    • YUI PHP Loader
    • Grid Builder »
    • Skin Builder »
  • YUI
  • >
  • Community
  • >
  • Gallery

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • Yogi Documentation
  • Shifter Documentation
  • Developer Guide
  • Module Setup

Tag Cloud

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    Arrow event (gallery-event-arrow) on cdn

    Last Updated: 02/9/11
    + 0 -

    Luke Smith

    YUI Contributor

    See 19 more by this user.

    Created: 01/5/11
    Last CDN Push: 01/18/11
    Build Tag: gallery-2011.01.18-21-05
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.3.0
    Free for use.

    The event passed to subscribers includes a property e.direction with value in ('n', 's', 'e', 'w', 'nw', 'ne', 'sw', 'se'). The event repeats as long as an arrow key remains depressed, and preventing the event with e.preventDefault() will stop native page scrolling.

    This event first saw life in gallery-event-nav-keys, then was explored a bit more in a YUI Event Utility example. The example is a simplified form of this one.

    • Tags:
    • lsmith
    • synthetic
    • event
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Here's an improved version of the Event Utility example "Creating an Arrow Event for DOM Subscription". The example synthetic arrow event supports only four directions.

    Code Sample

    <script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>
    // Use this in place of the current Event Utility 'arrow' example code
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2011.01.18-21-05'
    }).use('gallery-event-arrow', function(Y) {
     
        var robotA = Y.one('#A'),
            robotB = Y.one('#B');
     
        robotA.setData('x', parseInt(robotA.getStyle('left'), 10));
        robotA.setData('y', parseInt(robotA.getStyle('top'), 10));
        robotB.setData('x', parseInt(robotB.getStyle('left'), 10));
        robotB.setData('y', parseInt(robotB.getStyle('top'), 10));
     
        function move(e) {
            // to prevent page scrolling
            e.preventDefault();
     
            var xy = this.getData();
     
            switch (e.direction) {
                case 'n':  xy.y -= 10; break;
                case 's':  xy.y += 10; break;
                case 'w': xy.x -= 10; break;
                case 'e':  xy.x += 10; break;
                case 'nw': xy.y -= 10; xy.x -= 10; break;
                case 'ne': xy.y -= 10; xy.x += 10; break;
                case 'sw': xy.y += 10; xy.x -= 10; break;
                case 'se': xy.y += 10; xy.x += 10; break;
            }
     
            this.transition({
                top : (xy.y + 'px'),
                left: (xy.x + 'px'),
                duration: .2
            });
        }
     
        robotA.on("arrow", move);
        robotB.on("arrow", move);
     
        // Or via delegation
        Y.one('#demo').delegate('arrow', move, '.robot');
     
    });

    Forum Posts

    Subject Author Date
    trying to get a simple example to work... Andrew Wooldridge 03/23/11
    Re: trying to get a simple example to work... Andrew Wooldridge 03/24/11
    Re: trying to get a simple example to work... Andrew Wooldridge 03/24/11
    Re: trying to get a simple example to work... Luke Smith 03/25/11
    Advice on key &quot;holding&quot; issue? Andrew Wooldridge 03/28/11

    © 2006-2013 Yahoo! Inc. All rights reserved.
    All code on this site is licensed under the BSD License unless stated otherwise.
    About This Site · Security Contact Info