我在oen元素上获得了2个事件[mousedown,点击],但是第二个事件只是工作,当我点击图片旁边的时候[它在元素内部] ...我没有任何词语:)第二个事件[onClick]不起作用
下面是一个代码: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>
尝试按图像 - 事件将无法工作。 在图像上快速按两次即可使用。
为什么会发生?我该如何解决它?
您应该将任何相关的代码复制到您的问题中。如果你的外部链接失效,这个问题将来对其他人来说不会有任何用处。 – ste2425