user1942359
user1942359

Reputation: 1639

clicking is forbidden on canvas

I need to prevent clicking in some places of the canvas. For example; the canvas below. Between (0,250)-(0,300) coordinates as (x,y), if the user click anywhere in this interval nothing is gonna be.

<script>

window.onload = function(){
    document.getElementById('lbltipAddedComment').innerHTML = '  ';
    var canvas = document.getElementById("myCanvas");
    var context = canvas.getContext("2d");
}
</script>

<div id="ccontainer">
<canvas id="myCanvas" width="800" height="500"></canvas>   
</div>

Upvotes: 0

Views: 91

Answers (1)

Jayy
Jayy

Reputation: 14798

The canvas does not respond to clicks on its own. It needs code to do so. So as it stands, clicking is forbidden on the entire canvas by default. Your code will enable it to react to clicks. So just write your code to react to clicks in the way you want it to.

An easy way to do this would be position a transparent html element over the canvas (position it using CSS). Set an on-click handler, perhaps using JQuery, so when that transparent element is clicked, it performs the operation you desire.

Upvotes: 2

Related Questions