1
두 이미지가 서로 위에 쌓여 있습니다. img_top
에는 '포인터 이벤트 : 없음'이 설정되어 있으므로 클릭하면 img_bottom
으로 넘어갑니다. 그러나 jQuery의 trigger('click')
을 img_top
에 호출하면 클릭 수가 img_bottom
으로 전달되지 않습니다.CSS 포인터 이벤트를 트리거하지 않는 클릭 이벤트 : 없음
jQuery의 trigger('click')
과 CSS의 pointer-events
을 사용하여 이유를 설명하고 하단 이미지로 클릭을 전달하는 방법을 찾을 수 있습니까?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<style type="text/css">
#img_holder {
position: relative;
width: 20px;
height: 20px;
}
#img_bottom {
position: absolute;
background: url('/images/cross.png');
width: 16px;
height: 16px;
z-index: 1;
}
#img_top {
pointer-events: none;
position: absolute;
background: url('/images/tick.png');
width: 16px;
height: 16px;
z-index: 2;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$(document).click(function() {
alert('clicked');
$("img_top").trigger('click');
});
$("#img_bottom").click(function() {
alert('success');
});
});
</script>
<div id="img_holder">
<div id="img_top"></div>
<div id="img_bottom"></div>
</div>
이 제대로 작동하지만, 왜 "진짜"다음 통과를 클릭 doea? 어떻게 에뮬레이션 할 것인가? –
@AdrienHingert 실제 클릭은 마우스 위치를보고 이벤트를 발생시키는 올바른 요소를 결정하는 브라우저의 UI에 의해 처리되기 때문에 통과합니다. –
JS를 통해 위의 예처럼 통과 할 수있는 방식으로 "위장"될 수있는 방법이 있습니까? –