Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Swiper keyboard custom keys

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.

enter image description here

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use keyPress event with swiper.on method, like it's described here

Example:

swiper.on("keyPress", (swiper, keyCode) => {
  switch (keyCode) {
    case 38:
      swiper.slidePrev();
      break;
    case 40:
      swiper.slideNext();
      break;
  }
});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!