【发布时间】:2016-05-01 18:26:29
【问题描述】:
我在 oen 元素上得到了 2 个事件 [mousedown, click],但是当我单击图像旁边的 [它在元素内部] 时,第二个事件才起作用...我无话可说 :)
这是一个代码:codepen.io/Ivanowski/pen/JXeRpp
$('.ripple').on('mousedown', function(event){
// Check if shadow exists
if( $(this).find('.shadow').length == 0 )
$(this).append('<span class="shadow"></span>');
var shadow = $(this).find('.shadow');
// Remove animation if it exists
shadow.removeClass('animation');
// Set shadow size
if( !shadow.width() && !shadow.height() )
{
var size = Math.max($(this).outerWidth(), $(this).outerHeight());
shadow.css({
width: size,
height: size
});
}
// Set shadow left, top
var x = Math.round( event.clientX - this.getBoundingClientRect().left ) - ( shadow.width() / 2 );
var y = Math.round( event.clientY - this.getBoundingClientRect().top ) - ( shadow.height() / 2 );
shadow.css({
left: x+'px',
top: y+'px'
});
// Start animation
shadow.addClass('animation');
});
/*
* It does not work
*/
$('#switcher').on('click', function(){
console.log('aaa');
});
html
height: 100%
body
height: 100%
background: #183145
display: flex
align-items: center
justify-content: center
.swicher
padding: 9px 5px
cursor: pointer
.ripple
overflow: hidden
position: relative
.shadow
background: #fff
border-radius: 100%
position: absolute
transform: scale(0)
&.animation
animation: ripple 0.6s linear
@keyframes ripple
100%
opacity: 0
transform: scale(2.5)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<span id="switcher" class="swicher ripple">
<a href="#">
<img src="http://i.imgur.com/Ed2ShTk.png" alt="" />
</a>
</span>
尝试按下图像 - 事件不起作用。 快速按两次图像即可。
为什么会这样?我该如何解决?
【问题讨论】:
-
您应该将任何相关代码复制到您的问题中。如果您的外部链接失效,这个问题将来对其他人没有任何用处。
标签: javascript jquery events