slides.swap
というカスタムイベントを作成しましたが、trigger()
のclick
からのイベントを防ぐ必要があります。動いていない。 trigger()
からどうすればよいですか? 私はclick
機能でそれを防ぐことができますが、私はすべてを "カプセル化"しておきたいと思います。jQueryのtrigger()で.preventDefault()を使用することは可能ですか
JS:あなたはclick
イベントに異なるあるswap
イベントのイベントオブジェクトにpreventDefault()
を呼んでいる
tabs.on('click', 'a', function(e){
$(this).trigger('slides.swap', e);
});
//Custome event
tabs.find('a').bind('slides.swap', function(e){
var self = $(this),
selfIndex = self.parent().index(),
targetSlide = slides.eq(selfIndex);
e.preventDefault(); //somehow this doesn't work
//fade in/out slides
slides.filter('.active').stop(true, false).fadeOut(speed, function(){
$(this).removeClass('active');
});
targetSlide.stop(true, false).fadeIn(speed).addClass('active');
tabs.removeClass('selected');
self.parent().addClass('selected');
});
感謝
このカスタムイベントがなぜ必要なのかわかりません。無名関数を直接clickイベントにバインドできませんでしたか? – alextercete