The problem:
I'm building a photo gallery and I need to paginate the thumbnails. So, I put all the thumbnails inside a carousel and by clicking the arrows I change the page. So far, so good.
I need to be able to move through the thumbnails with the keyboard arrows. The problem is that the carousel itself has a keydown
bind. So if for example I click on an arrow, the page changes but then, if a press a keyboard's arrow, I trigger the keydown
of the carousel, which I don't want to.
The question:
Is there a way to disable the keydown
of the carousel without modify the bootstrap.js? Because I'm using it through a CDN.
In the carousel.js I found this:
...
var Carousel = function (element, options) {
this.$element = $(element).on('keydown.bs.carousel', $.proxy(this.keydown, this))
...
Carousel.prototype.keydown = function (e) {
switch (e.which) {
case 37: this.prev(); break
case 39: this.next(); break
default: return
}
e.preventDefault()
}
But I don't know how to override it. I tried with $('.carousel').off('keydown');
and $('.carousel').off('keydown.bs.carousel');
but nothing happened.
I leave you a simplify version of my thumbnails for you to try: JSFiddle.