From ProtoScript
Contents |
YUI:Keypress Behavior
Adds a keypress event to the current behavior or callback.
Example
$proto('document', {
Keypress: {
key: 'escape',
onKeypress: {
Fade: {
opacity: {to: 0}
}
}
}
});
When the user presses the 'Escape' key when the selected element(s) has focus, fire the onKeypress event.
Attributes
| Name | Description | Default | Valid Values | Example |
|---|---|---|---|---|
| target | Selected element or elements to attach a double-click event to. See Element Scope | Inherited from parent behavior. If no value supplied, use the last targeted element. If value is supplied, use the element(s) selected by the target instead. | String value denoting an interface element. | target:'#avatar' |
| key | Name of key that must be pressed for the event to fire | Any character (e.g., 'a', '%', '+'). Also 'escape', 'enter', 'tab' | no value | 'escape' |
| delay | Amount of time (in seconds) to delay before firing the callback behavior. | No delay is set. | number | delay: 0.5 |
Callbacks
| Name | Description |
|---|---|
| onKeypress | The callback corresponding to the Keypress behavior. Fired when a keypress event happens on the target. If the modifier attribute is supplied, then the given modifier key must be pressed also. If a keycode is supplied, the event will fire if it matches the keycode. |
Demos
See Keypress Demo
