Skip to content

Instantly share code, notes, and snippets.

@ericwwsun
Created June 26, 2012 21:01
Show Gist options
  • Save ericwwsun/2998980 to your computer and use it in GitHub Desktop.
Save ericwwsun/2998980 to your computer and use it in GitHub Desktop.
Javascript: Keyboard navigation control, Vertically
// --------- keyboard navigation control --------- //
var isinmotion = false;
$j(document).keydown(function(e){
switch (e.keyCode) {
case 38:
//console.log("up");
if (isinmotion) {
return false;
} else {
var curr = $j("li.viewing:last");
var prev = curr.prev("li");
if(prev.size() > 0 ) {
isinmotion = true;
$j(window).scrollTo( prev, 800, {easing:'swing', onAfter:function(){
isinmotion = false;
}});
}
}
return false;
break;
case 40:
//console.log("down");
if (isinmotion) {
return false;
} else {
var curr = $j("li.viewing:last");
var next = curr.next("li");
if(next.size() > 0) {
isinmotion = true;
$j(window).scrollTo( next, 800, {easing:'swing', onAfter:function(){
isinmotion = false;
}});
}
}
return false;
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment