There are a few simple plugins that I have made that make this much deeper. It requires much less code than the proposed solutions, and it is very lightweight (~ 0.6kb)
First you create a Bid object than can be bumped at any time. Each hit slows the Bid callback for the next specified time.
var searchBid = new Bid(function(inputValue){
When the Bid object is ready, we need to bump it somehow. Let the slope be attached to the keyup event .
$("input").keyup(function(){ searchBid.bump( $(this).val() );
What is going on here:
Each user presses a key, the bet is "delayed" (filled) for the next 200 ms. If 200 ms pass without unnecessary hits, the callback will be launched.
In addition, you have two additional functions for stopping the bet (if the user pressed esc or pressed an external input, for example), as well as for immediate completion and immediate completion of the callback (for example, when the user presses the enter key):
searchBid.stop(); searchBid.finish(valueToPass);
pie6k Apr 23 '15 at 11:39 on 2015-04-23 11:39
source share