mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
nav: fix left/right navigation for horizontal scrolling #435
This commit is contained in:
parent
1ee561fd77
commit
05b31c174a
1 changed files with 38 additions and 6 deletions
|
@ -369,13 +369,45 @@ function initArrowNav(){
|
||||||
});
|
});
|
||||||
|
|
||||||
// keyboard navigation
|
// keyboard navigation
|
||||||
jQuery(document).keydown(function(e) {
|
// avoid prev/next navigation if we are not at the start/end of the
|
||||||
if(!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey){
|
// horizontal area
|
||||||
if(e.which == '37') {
|
var el = document.querySelector('#body-inner');
|
||||||
jQuery('a.nav-prev').click();
|
var scrollLeft = 0;
|
||||||
|
var scrollRight = 0;
|
||||||
|
document.addEventListener('keydown', function(event){
|
||||||
|
if( !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ){
|
||||||
|
if( event.which == '37' ){
|
||||||
|
if( !scrollLeft && el.scrollLeft <= 0 ){
|
||||||
|
jQuery('a.nav-prev').click();
|
||||||
|
}
|
||||||
|
else if( scrollLeft != -1 ){
|
||||||
|
clearTimeout( scrollLeft );
|
||||||
|
}
|
||||||
|
scrollLeft = -1;
|
||||||
}
|
}
|
||||||
if(e.which == '39') {
|
if( event.which == '39' ){
|
||||||
jQuery('a.nav-next').click();
|
if( !scrollRight && el.scrollLeft + el.clientWidth >= el.scrollWidth ){
|
||||||
|
jQuery('a.nav-next').click();
|
||||||
|
}
|
||||||
|
else if( scrollRight != -1 ){
|
||||||
|
clearTimeout( scrollRight );
|
||||||
|
}
|
||||||
|
scrollRight = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
document.addEventListener('keyup', function(event){
|
||||||
|
if( !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ){
|
||||||
|
if( event.which == '37' ){
|
||||||
|
// check for false indication if keyup is delayed after navigation
|
||||||
|
if( scrollLeft == -1 ){
|
||||||
|
scrollLeft = setTimeout( function(){ scrollLeft = 0; }, 300 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( event.which == '39' ){
|
||||||
|
if( scrollRight == -1 ){
|
||||||
|
scrollRight = setTimeout( function(){ scrollRight = 0; }, 300 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue