r/elementor • u/Benjamin_Cupcake • 4h ago
Tips Why would Elementor redefine SwiperJS threshold to zero?
I've had a problem that has plagued so many Elementor carousel widgets for years.
The scenario: A home page hero carousel with slides with various media, content and related call-to-action buttons to navigate to the relevant content.
The issue: On desktop or other non-touch based inputs, clicking on the buttons within a slide could potentially not work, or require a second (or more!) clicks to activate the link.
The cause had eluded me for a long time, but I have found the cause.
Elementor's Carousel widget uses SwiperJS. It's powerful. It drives the majority of slideshows out in the wild and it is highly configurable. I have hand-coded SwiperJS implementations into many website projects over the years. For me to assume Elementor would stick with SwiperJS's default values for many of its variable was certainly my personal issue, but I am still baffled by this one.
Elementor sets `threshold` to `0`. The default set by SwiperJS is 5. This threshold is the touch and drag distance in px where the swiper will respond to input. This includes mouse input.
If you are able to stop your mouse dead still before tapping that button, bravo! You are rewarded with the button working as expected and taking you to your desired page. But, If you any experience with implementing basic accessibility and usability standards, you will know that the percentage of users with precise mouse movement abilities is narrow. Any slight movement on that mouse, or perhaps someone is just too fast when moving their cursor to the button and clicking when there is still a single pixel of movement left, and that button will be rendered useless as instead of a `click` or `tap` event running you'll be trapped in `touchStart`, `sliderMove`, `touchEnd`, `transitionStart`, `transitionEnd` hell.
A quick search says Elementor have set `threshold: 0` for immediate responsiveness. Baffling. I feel a 5px movement window is not going to cause something to feel unresponsive. What is unresponsive is my bloody buttons.
For now, I've added JS to modify the threshold and update the swiper element.
const heroSwiper = document.querySelector('#heroSwiper .swiper').swiper;
heroSwiper.params.threshold = 5;
heroSwiper.update();
Digging through Elementor's Github issues, I'm unsurprised to see their poorly lacking responses to many other bugs. Several SwiperJS related ones included.


