How to fix problem with clicking event on bxSlider item in Chrome 73?
Asked Answered
J

3

10

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/

Jevons answered 28/3, 2019 at 2:43 Comment(2)
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); } }); ```Jevons
I found this solution and it works: "It works on Chrome when you add touchEnabled: false" support.google.com/chrome/thread/3211737/… но и ваше решение тоже работаетLenticularis
M
16

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

Methodism answered 29/3, 2019 at 17:1 Comment(3)
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 google.ru/… - ther is no link to this page.Jevons
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 chromestatus.com/feature/5745543795965952" But I don't know, was it before update, or no. I'll try solution, may be it helps.Jevons
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.Jevons
M
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"); 
        } 
    }); 
}
Misdemean answered 4/4, 2019 at 10:5 Comment(1)
This is the solution! ThanksGloom
I
-1
$('.bxslider').bxSlider({
    touchEnabled: false,
});
Idea answered 17/4 at 7:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.