Created
January 26, 2010 20:25
-
-
Save philhawksworth/287186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>an example of a pause before a look ahead search</title> | |
</head> | |
<body> | |
<input type="text" id="search-box"> | |
<p id='result'></p> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> | |
<script type="text/javascript" charset="utf-8"> | |
// wait for the document to be ready before we start. | |
$(document).ready(function() { | |
// Create a variable to hold a reference to a timer for the delay | |
var searchPause; | |
// listen for a kepress. | |
$('#search-box').keypress(function(){ | |
// clear any previous delays | |
clearTimeout(searchPause); | |
// create a new delay. | |
searchPause = setTimeout(function(){ | |
// do things if the delay runs it's course. | |
goSearching(); | |
}, 500); // the length of the delay in milliseconds (300 would be a good value, I think.) | |
}); | |
}); | |
function goSearching() { | |
var timestamp = new Date(); | |
$('#result').text(timestamp.getTime()); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment