• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

31
Views
Triger Next Prev function button when clicking the left right key

good day everyone... badly needed help how can I trigger the next prev function if I press the left and right arrow keys. this is for the slider/lightbox that I was assign into.

this is the code

$(document).ready(function() {
  var currentIndex = 0,
    navItems = $(".navindex");

  function setSlide(index) {...}

  $(".navindex").click(function() {
    var index = $(".navindex").index($(this));
    currentIndex = index;
    setSlide(currentIndex);
  });


  function next() {
    if (currentIndex < navItems.length - 1) {
      currentIndex++;
      setSlide(currentIndex);
    }
  }

  $(".next").click(function() {
    next();
  });

  function prev() {
    if (currentIndex > 0) {
      currentIndex--;
      setSlide(currentIndex);
    }
  }

  $(".prev").click(function() {
    prev();
  });


  function slide() {
    if (currentIndex < navItems.length - 1) {
      currentIndex++;
      setSlide(currentIndex);
    } else {
      currentIndex = 0;
      setSlide(currentIndex);
    }
  }

});

about 1 month ago ·

Juan Pablo Isaza

1 answers
Answer question

0

You want to handle key events. Something along the lines of:

$(document).keyup((evt) => {
  if (evt.key === 'ArrowLeft')
    return prev();
  if (evt.key === 'ArrowRight')
    return next();
});
about 1 month ago · Juan Pablo Isaza Report
Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.