question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Click (touch) inside items doesn't work on iOS

See original GitHub issue

Hi. I’m trying to use Slick to display offers. Every offer has a button, that can be clicked (touched). If property mobileFirst set to false - on desktop everything works fine, but on iOS 7 Safari and Chrome jQuery $('hot-tour-button').on('click' function(){...}) doesn’t work. If property mobileFirst set to true - iOS starts work with click event, but desktop borwsers don’t catch this.

$(document).ready(function() { 
    var SLICKconfig = {
        infinite: true,
        slidesToShow: 3,
        slidesToScroll: 1,
        autoplay: true,
        mobileFirst:false,
        autoplaySpeed: 5000,
        prevArrow:"<div class='visible-lg vv-slick-prev'><img src='/img/arrow.png'></div>",
        nextArrow:"<div class='visible-lg vv-slick-next'><img src='/img/arrow.png' class='rotate'></div>",
        responsive: [
            {
              breakpoint: 1200,
              settings: {
                slidesToShow: 3,
                slidesToScroll: 1,
              }
            },
            {
              breakpoint: 1024,
              settings: {
                slidesToShow: 2,
                slidesToScroll: 1
              }
            },
            {
              breakpoint: 768,
              settings: {
                slidesToShow: 1,
                slidesToScroll: 1
              }
            }
        ],
    };
    $(".carousel-contaner").slick(SLICKconfig);
});
$(".hot-tour-button").on('click',function(){
        toggleShadow();
    });

How should I configure Slick to make click work both, on desktop and mobile devices?

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:13

github_iconTop GitHub Comments

13reactions
mikerogerzcommented, Mar 13, 2015

My solution was to use event delegation (jquery’s “.on()” method) from outside of the carousel’s top element (with the “slick-slider” class), targeting the elements inside the carousel. This way the event handler is unaffected by the bug.

Example:

$('.carousel-container').on('click', 'div.button', function() {
  // do stuff
});
7reactions
Jakobudcommented, Mar 16, 2017

@mikerogerz solution works perfectly. In my experience it doesn’t even appear that I need to bind this to an extra outside container element. I just use this and it works perfectly:

$('.slick-slider').on('click', '.slick-slide', function(){
  // This click event will not trigger when you drag the carousel
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

iPhone Not Responding To Touch? Here's The Fix! [2022]
David & David explain why your iPhone is not responding to touch and show you how to fix the problem for good. This...
Read more >
Adjust how iPhone responds to your touch
Go to Settings > Accessibility > Touch > Touch Accommodations, then turn on Touch Accommodations. You can configure iPhone to do any of...
Read more >
Navigation Item's click or touch event sometimes does not ...
I solved this problem by using UITapGestureRecognizer and UIImageView . I added both default UIBarButtonItem and customized UIBarButtonItem ...
Read more >
iOS 16 Problems and Bugs with Fixes in 2022
Go to Settings> Accessibility > Touch>Turn ON Touch Accommodations>Select Use Initial Touch Location. Then turn on Swipe Gestures and select ...
Read more >
How to customize your lock screen and 9 other iOS 16 tricks
Tap on Add Widgets under the time on your new screen and pick up to four small options or two big ones for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found