2013-03-10 56 views
0

我在网页上有一个画布全屏。 大小可以在processingjs中处理。忽略全屏画布

 <div id="canvasDiv"> 
      <canvas id="processingCanvas" data-processing-sources="resources/processing/canvas01.pde"> </canvas> 
     </div> 

画布后面有很多文字。问题是我无法在iPad上滚动,导致画布处于顶部。 有没有办法忽略画布,但仍然显示在上面? 这是当前的CSS:

#canvasDiv { 
    position: absolute; 
    left: 0; 
    z-index: 999; 
} 



#processingCanvas { 
    position: fixed; 
    top: 0; 
    left: 0; 
} 

回答

0

这里是如何让元素始终陷入底层元素:

如果浏览器是Chrome浏览器,火狐,Safari,黑莓或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>