jamland
jamland

Reputation: 971

How to change default keyboard shortcuts behaviour for Swiper.js?

I would like overwrite default routine for left/right keys but can't find how to do this via Swiper.js API (http://idangero.us/swiper/api/#keyboard)

Looks like it is only provide way to disable/enable default actions:

mySwiper.keyboard.enabled       // Whether the keyboard control is enabled
mySwiper.keyboard.enable()      // Enable keyboard control
mySwiper.keyboard.disable()     // Disable keyboard control

Upvotes: 2

Views: 2474

Answers (1)

Marco
Marco

Reputation: 279

Since you can't really overwrite default behaviour, i guess your best choice would be to write your own event handler after disabling default actions.

document.addEventListener("keydown", function(e){
    if(e.keyCode == 37) {
        mySwiper.slidePrev(); 
        //Left arrow pressed
    }
    if(e.keyCode == 39) {
        mySwiper.slideNext();
        //Right arrow pressed
    }   
});

Extra: Keycodes

Upvotes: 4

Related Questions