我有一些span
和一个button
紧随其后。我想要做的就是隐藏span
元素并在指针位于按钮位置时触发button
点击事件。
但是我无法做到这一点,因为点击事件直接进入span
事件处理程序。我尝试使用pointer-events: none
来实现,但在这种情况下,我将无法附加mouseover
事件。
还尝试设置CSS display: none
,但在这种情况下,事件处理程序不会被附加。
有没有办法做到这一点?
$('#myspan').on('mouseenter', function (event) {
$(this).animate({ 'opacity': 0 });
});
$('#myspan').on('mouseleave', function (event) {
$(this).animate({ 'opacity': 0.5 });
});
$('#clicker').on('click', function(event) {
alert('result');
})
#myspan {
position: fixed;
font-size: 22px;
z-index:500;
position: fixed;
left: 50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id='myspan'>{{property}}</span>
<button id='clicker' style='width: 250px; height: 20px; left: 40%; z-index: -1; position: absolute'>
Clicker
</button>
pointer-events: none
,那么我将无法将mouseenter
和mouseleave
事件附加到该 span 上,但我确实需要它们。 - user8393506