9

A bxSlider's inner item click event doesn't fire after Chrome has updated to version 73. How can I fire .on('click') event for elements in new Chrome?

It fires in Chrome when slides are moving. Everyting is fine in FireFox

<div class="slider-pager">
  <div class="slider-pager__item"><img src="1.jpg" alt=""></div>
  <div class="slider-pager__item"><img src="2.jpg" alt=""></div>
</div>

<script>
        carouselProduct = $('.slider-pager').bxSlider({
            maxSlides:  3,
            minSlides: 3,
            slideWidth: 90,
            infiniteLoop: false,
            moveSlides: 1,
            slideMargin: 8,
            pager: false,
            nextSelector: '.slider__nav--next',
            prevSelector: '.slider__nav--prev',
            nextText: '→',
            prevText: '←'

        });
  $('.slider-pager__item').on('click', function (event) {
    //Don't fire in Chrome 73, works in FireFox
            $('.slider-pager__item').removeClass('active');
            $(this).addClass('active');

        });
</script>

JS Fiddle https://jsfiddle.net/sergey_beloglazov/3ty7w12z/17/

UPDATE: I have made a workaround for this slider, handling wrapper onClick event:

$('.slider-pager').parent().on('click', function (event) {
    var $hover_item = $('.slider-pager__item:hover');
    //Checking if we have found the element
    if ($hover_item.length>0){
        selectBxPagerItem($hover_item);
    }
});

$('.slider-pager__item').on('click', function (event) {
    selectBxPagerItem($(this));
});

selectBxPagerItem() - is a selecting function. For a slider with colorbox on click, I have made a similar click emulation:

        $('.slider-for').parent().on('click', function (event) {
            var $hover_item = $('.slider-for__item:hover a');
            if (($hover_item.length>0)&&(!window.slider_for_click_imitation)){
                window.slider_for_click_imitation=true;
                $hover_item.click();
            }
            window.slider_for_click_imitation=false;
        });

UPDATE 2019.07.20: I've found out recently, that previous solution doesn't work now. I've cheked it and discover, that inner elements have no :hover state; So, there is another soulution with mouseover event

/* A Chrome bx slider bug workaround */

//A slide, that has the mouse pointer over
window.bxslider_mouse_over_slide=null;
$(function() {
    $('.slider-pager div').mouseover(
        function(event) {
            window.bxslider_mouse_over_slide=$(this);
        });

});
$('.slider-pager').parent().on('click', function (event) {
    //Check if we've got a slide under the mouse
    if ((window.bxslider_mouse_over_slide!=null)){
            $('.slider-pager__item').removeClass('active');
        window.bxslider_mouse_over_slide.addClass('active');
    }
});

Making a workaround, I've found out that when I click on banner, a mouseover event triggers, and only then it handles a click event. So that that moment slide has no :hover state. So I just save last hovered banner. Check the solution: https://jsfiddle.net/sergey_beloglazov/5kmdacgn/22/

Sergey Beloglazov
  • 160
  • 1
  • 2
  • 12
  • I have made a workaround for this slider: ``` $('.slider-pager').parent().on('click', function (event) { var $hover_item = $('.slider-pager__item:hover'); //Проверяем, нашли ли элемент if ($hover_item.length>0){ selectBxPagerItem($hover_item); } }); ``` – Sergey Beloglazov Mar 28 '19 at 04:08

2 Answers2

13

Looks like the latest Chrome update made any click inside bxSlider target the container instead the link inside it.

Adding touchEnabled: false to the options disables the swipe behaviour, but solves the click issue. Eg.:

 carouselProduct = $('.slider-pager').bxSlider({
            maxSlides:  3,
            minSlides: 3,
            slideWidth: 90,
            infiniteLoop: false,
            moveSlides: 1,
            slideMargin: 8,
            pager: false,
            nextSelector: '.slider__nav--next',
            prevSelector: '.slider__nav--prev',
            nextText: '→',
            prevText: '←',
            touchEnabled: false
        });

I recommend keeping an eye/contributing to this thread for updates and better solutions: https://github.com/stevenwanderski/bxslider-4/issues/1240

Osmar Matos
  • 342
  • 1
  • 9
  • Thank you for your github link! It's a pity, I didn't manage to find it with google, though I spend a lot of time searching for fix in internet You can try https://www.google.ru/search?q=Links+in+sliders+aren%27t+working+Error+in+the+latest+version+of+Chrome - ther is no link to this page. – Sergey Beloglazov Apr 01 '19 at 18:43
  • Also I had a violation in Chrome console every time I click on bxSlider image: "[Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952" But I don't know, was it before update, or no. I'll try solution, may be it helps. – Sergey Beloglazov Apr 01 '19 at 18:44
  • 1
    I tried "touchEnabled : (navigator.maxTouchPoints > 0)" Violations in Chrome console had dissapeared, But banners stopped moving by swipe on iPad. So I think It's not a complete solution. I won't use it. Also I read some people went on an old version of bxSliders, but I don't want that too.Other solutions concerns plugin code changing. It seems too risky for me. My solution works fine, it fits me. So I have only some worries about violations in Chrome console now. – Sergey Beloglazov Apr 02 '19 at 21:01
7

I used the mousedown event instead

if(window.navigator.userAgent.toLowerCase().indexOf("chrome") > 0) {
    $("body").on("mousedown", ".bx-viewport a", function() { 
        if($(this).attr("href") && $(this).attr("href") != "#") {
            window.location=$(this).attr("href"); 
        } 
    }); 
}
Antoine
  • 71
  • 1