I have a horizontal Swiper and keyboard enabled, which means I can swipe using left and right keys. But I want to be able to swipe using top and bottom keys as well. I wrote this script, but it doesn't work, does anyone have an idea why?
$(document).ready(function() {
var swiper = new Swiper('.swiper', {
direction: 'horizontal',
slidesPerView: 1,
speed: 600,
effect: 'fade',
keyboard: {
enabled: true,
},
});
swiper.addEventListener("keydown", function(e) {
if (e.key == 38) {
swiper.slidePrev();
}
if (e.key == 40) {
swiper.slideNext();
}
});
});
I also read this documentation, maybe this is the easier way to assign custom keys, but I have no idea how to use it.