Juan Ignacio Dopazo![]()
Debouncing is a similar strategy to throttling (see yui-throttle)
`Y.debounce` delays the execution of a function by a certain number
of milliseconds, starting over every time the function is called.
That way it allows you to listen only once to events happening
repeated times over a time span.
For example, you can debounce a callback to a keypress event so that you know when a user stopped typing:
<script src="http://yui.yahooapis.com/3.10.0/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2013.05.15-21-12'
}).use('gallery-debounce', function(Y) {
// You'll only get notified if the user stops typing (or types really slow)
Y.one('input').on('keypress', Y.debounce(500, function () {
alert('The user stopped typing');
}));
});
© 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