Skip to content

Instantly share code, notes, and snippets.

@DrewDahlman
Created July 10, 2012 17:56
Show Gist options
  • Save DrewDahlman/3085142 to your computer and use it in GitHub Desktop.
Save DrewDahlman/3085142 to your computer and use it in GitHub Desktop.
waypoints
window.onkeydown = function(event){
keyboard.press(event.keyCode);
}
}());
var $panes = $(".waypoint").length-1;
var $currentPane = $(".waypoint").first();
var keyboard = {
press:function(keycode){
console.log(keycode);
switch(keycode){
case 74:
//model_nav.killWaypoint();
if($currentPane.index()>=$panes){
$currentPane = $currentPane.next('.waypoint');
}
else {
$currentPane = $(".waypoint").first();
}
var go = $currentPane.offset().top-65;
$('html,body').stop().animate({scrollTop:go},function(){
//model_nav.listenWaypoint();
});
break;
case 75:
//model_nav.killWaypoint();
if($currentPane.index()<=-1){
$currentPane = $(".waypoint").last();
}
else {
$currentPane = $currentPane.prev('.waypoint');
}
var go = $currentPane.offset().top-65;
$('html,body').stop().animate({scrollTop:go},function(){
//model_nav.listenWaypoint();
});
break;
case 40:
//model_nav.killWaypoint();
if($currentPane.index()>=$panes){
$currentPane = $currentPane.next('.waypoint');
}
else {
$currentPane = $(".waypoint").first();
}
var go = $currentPane.offset().top-65;
$('html,body').stop().animate({scrollTop:go},function(){
//model_nav.listenWaypoint();
});
break;
case 38:
//model_nav.killWaypoint();
if($currentPane.index()<=-1){
$currentPane = $(".waypoint").last();
}
else {
$currentPane = $currentPane.prev('.waypoint');
}
var go = $currentPane.offset().top-65;
$('html,body').stop().animate({scrollTop:go},function(){
//model_nav.listenWaypoint();
});
break;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment