metafizzy / flickity-docs

:memo: documentation for Flickity
28 stars 8 forks source link

staticClick on individual element #26

Closed ghost closed 8 years ago

ghost commented 9 years ago

Hi, I'm using your slider and for the most part it's great but I do have this issue where I have multiple element in the slider and within each element I have a couple of buttons that trigger specific events using Javascript. I'm trying to use the staticClick function on these but I can't figure out how.

Basic structure is:

// the element in the slider Button one // trigger event one Button two // trigger event two

So basically, I need the buttons to only trigger their events on staticClick and not on the standard click event in JS.

Any help would be greatly appreciated.

desandro commented 9 years ago

Thanks for reporting this issue. One way to do this is to use event to determine what was actually clicked. If you're using jQuery, get the clicked element with event.originalEvent.target. You can then you can get a parent element .closest(). See demo http://codepen.io/desandro/pen/xwYgPV?editors=001

$gallery.on( 'staticClick', function( event ) {
  var $button = $(event.originalEvent.target).closest('button');
  if ( $button.length ) {
    $logger.text( $button.attr('class') + ' clicked')
  }
});