要素を下層の要素にフォールスルーさせる方法は次のとおりです。
ブラウザーが Chrome、Firefox、Safari、Blackberry、または Android であり、IE や Opera ではない場合、ポインター イベントを使用して、クリック/タッチ イベントを処理しないようにキャンバスに指示すると、クリック/タッチは下層の要素によって処理されます。 . したがって、CSS では次のようになります。
#topCanvas{ pointer-events: none; }
しかし、IE と Opera では注意が必要です。
- トップキャンバスを隠し、
- 一番下の要素でイベントをトリガーし、
- トップキャンバスを表示します。
このコードは、基になる要素でイベントをトリガーする方法を示しています。
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
body{ background-color: ivory; }
#wrapper{ width:200; height:200;}
#bottom{ position:absolute; top:0; left:0; width:200; height:200; background-color:red; }
#top{ position:absolute; top:0; left:0; width:200; height:200; background-color:blue; }
</style>
<script>
$(function(){
$('#top').click(function (e) {
$('#top').hide();
$(document.elementFromPoint(e.clientX, e.clientY)).trigger("click");
$('#top').show();
});
$("#bottom").click(function(){ alert("bottom was clicked."); });
}); // end $(function(){});
</script>
</head>
<body>
<div id="wrapper">
<canvas id="bottom"></canvas>
<canvas id="top"></canvas>
</div>
</body>
</html>