简体   繁体   中英

Keyboard arrow keys navigation with Cbp image Slider

I'm trying to edit the CBP Slider to allow the keyboard's arrow keys to navigate the slideshow.Keyboard keys are not working for the slider

I have tried the below code, but not working for my requirement:-

<script>

    function handleKeyboardNav(e) {
        if (!e) e = window.event;
        var kc = e.keyCode;
        if (kc == 37) nslider.prev();
        if (kc == 39) nslider.next();
    }

    function bindKeyDownListener() {
        if (document.addEventListener)
            document.addEventListener("keydown", handleKeyboardNav, false);
        else if (document.attachEvent)
            el.attachEvent("onkeydown", handleKeyboardNav);
    }
         bindKeyDownListener();

</script>

any suggestion would be greatly appreciated.

Take a look at mousetrap which is a simple library for handling keyboard shortcuts. Remember that you need to use return false; after calling your selected function in the bind method to prevent the default action of the keyboard key being performed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM