Search code examples
javascriptowl-carouselowl-carousel-2

Carousel slide on keyboard click


I would like to make my owl carousel slide on keyboard click, specially on arrow left/right. How can i do it? My JS:

      loop: true,
        lazyLoad: true,
        autoplay: true,
        animateIn: 'fadeIn',
        animateOut: 'fadeOut',
        slideSpeed: 300,
        paginationSpeed: 400,
        dots: true,
        items: 1,
        itemsDesktop: false,
        itemsDesktopSmall: false,
        itemsTablet: true,
        itemsMobile: false

Thanks


Solution

  • Try something like this

    $(document).keydown( function(eventObject) {
       if(eventObject.which==37) {//left arrow
          $('.owl-prev').click();//emulates click on prev button
      } else if(eventObject.which==39) {//right arrow
         $('.owl-next').click();//emulates click on next button
       }
    });
    

    Refer : https://github.com/OwlCarousel2/OwlCarousel2/issues/110