【发布时间】:2014-06-20 13:53:10
【问题描述】:
我正在使用 FancyBox --> jQuery Plugin 来显示图片库。
这是一个我正在尝试使用的 JSFIDDLE:--> http://jsfiddle.net/CWaHL/238/
我希望用户能够删除图像,因此我在缩略图顶部创建了一个按钮。该按钮将出现,并且“鼠标悬停”上的不透明度会发生变化:
我可以单击垃圾桶按钮并触发事件(警报)。问题是 FancyBox 在第一个事件之后也会立即触发(因为按钮位于其父锚点内)。
如果我想让它正常工作,我只需要让垃圾桶按钮触发一个事件,然后阻止来自 FancyBox 的任何事件。
这是我的 HTML:
<a class="fancybox-thumbs" data-fancybox-group="thumb" href="[path to main image]">
<button class="btn btn-danger btn-icon delete_image_btn">
<i class='fa fa-trash-o'></i>
</button>
<img src="[path to thumbnail]" alt="" class='tip' data-placement='top' title='oldman, robot, dance'>
</a>
一些 jQuery:
$('.fancybox-thumbs').on('mouseover',function() {
$(this).children('img').css('opacity', '0.2');
$(this).children('button').css('display','block').css('opacity','1');
});
$('.fancybox-thumbs').on('mouseout',function() {
$(this).children('img').css('opacity', '1');
$(this).children('button').css('display','none');
});
// My failed attempt to prevent default click
$('.delete_image_btn').click(function() {
alert('sup');
$(this).parent('.fancybox-thumbs').prop('onclick', null);
});
【问题讨论】:
标签: jquery button onclick preventdefault