javascriptcssbxslider

Prevent bxSlider from going to link while swiping


I am trying to disable link on images inside bxSlider, while we swipe on mobile.

This, as you might imagine, is very annoying.

As far as I could see in their documentation (https://bxslider.com/options/) I couldn't find anything to do that.

I have also Googled some suggestions and tried some JS, but so far I couldn't make it happen.

I also tried setting "draggable='true'" on each slide element but, with no avail.


Solution

  • You can disable link clicks using addEventListener and removeEventListener in BxSlider's onSlideBefore and onSlideAfter callbacks respectively.

    Example:

    $('.bxslider').bxSlider({
        // ...
        onSlideBefore: function() {
             $('.bxslider a').on('click', function() {
                  return false;
             });
        },
        onSlideAfter: function() {
             $('.bxslider a').off('click');
        }
    });