slick: Swiping triggers click, not always wanted

A change from 1.3.10 where you removed return false is giving me a behavior I don’t want.

Swiping a video counts as a click and plays the video offscreen: http://codepen.io/matthewlein/pen/miFJs

It could be the wistia.js code doing weird stuff, but 1.3.10 was perfect for me. Could this click behavior be opted in or out, or as an alternative the return false, could you instead use a custom event like .trigger('slideClick.slick') or something like that to give people a click hook?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 1
  • Comments: 21 (6 by maintainers)

Most upvoted comments

Code for the already described solution:

carousel.slick();

var isSliding = false;

carousel.on('beforeChange', function() {
    isSliding = true;
});

carousel.on('afterChange', function() {
    isSliding = false;
});

carousel.find(".foo").click(function() {
    if (isSliding) {
        return;
    }
    
    // ...
});

After searching two days i found this and it helps. What i needed to, was to stop the Default Event while sliding like: carousel.find(".foo").click(function() { if (isSliding) { event.stopImmediatePropagation(); event.stopPropagation(); event.preventDefault(); return; } });

You’re right, but in that context i don’t think anyone expects to swipe-click on a static element.

I did build a workaround for supressing and unsupressing default click based on slick beforeChange and afterChange events, so my earlier observation can be ignored.

Thank you for getting involved and being so responsive, the plugin is tremendously helpful!

No action needed. Found a good solutions. Used that kind of event binding @mikerogerz mentioned in this issue: https://github.com/kenwheeler/slick/issues/1015

@kayzee I think that logic is already in slick here: https://github.com/kenwheeler/slick/blob/ef16dc13ebdd0d0a8776b24c5cf19b3178d0e879/slick/slick.js#L1748 But I’m not sure it works in the way we need it to. @kenwheeler maybe you can clarify.

For my case, and probably the others, clicks and touchends should not fire when a swipe triggers a slide advance, only when the swipe isn’t long enough and the slide snaps back to place. _shouldClick seems like it should work for this, but it doesn’t…