You're not calling your goToByScroll
function with an argument when you use the keyboard navigation - it looks like that's why it's not working. You'll need to keep track of your active dataslide so that you can pass that variable to your goToByScroll
function in your keyhandlers.
It'd look something like this (this is really crude):
var currentDataSlide = 0;
function goToByScroll(dataslide) {
htmlbody.animate({
scrollTop: $('.slide[data-slide="' + dataslide + '"]').offset().top
}, 2000, 'easeInOutQuint');
currentDataSlide = dataslide;
}
mywindow.keydown(function(e) {
if(e.keyCode == 40) { //DOWN
e.preventDefault();
alert('Down Arrow Has Been Pressed');
goToByScroll(currentDataSlide + 1);
}
else if (e.keyCode == 38) { //UP
e.preventDefault();
alert('Up Arrow Has Been Pressed');
goToByScroll(currentDataSlide - 1);
}
});
That's not perfect, but the idea is to keep track of where you are (slide-wise) and pass that variable when you use your keyhandlers.