The problem is the following, my canvas width and height is relative to its parents. In css, its width and height is set to 95%. That causes my getMousePosition function to not work properly, meaning that when I click on a canvas point, the actual point where say a rectangle is drawn is far from the observed clicked point.
Here is the html stuff
<div class="Container">
<div id = 'left-div'>
<canvas class = "Blackboard" id = "blackboard-canvas" >
</canvas>
</div>
<div id='right-div'>
<div id = 'tools-div'>
<ul>
<li><a href='#colorOption'>Color Options</a></li>
<li><a href='#toolbar-option'>Tool Bar</a></li>
</ul>
<div id='colorOption'>
<canvas id='color-option-canvas' >
</canvas>
</div>
<div id='toolbar-option'>
Tool bar options goes here
</div>
</div>
</div>
<br style="clear:both;"/>
</div>
and the relavent css
.Blackboard{
border-style: ridge;
border-color: gray;
border-width: 5px;
width: 96%;
height: 96%;
cursor: crosshair;
position: relative;
-webkit-border-radius: 16px;
-webkit-box-shadow: 0px 6px 7px #0a0505;
};
.Blackboard:active{
cursor: crosshair;
}
.Container{
border-color: #666;
border-width: 10px;
border-style: inset;
background-color: gray;
width: 700px;
height: 400px;
}
#right-div, #left-div{
height: 100%;
}
#left-div{
float: left;
width: 60%;
}
#right-div{
float: right;
background-color: black;
width: 40%;
}
Is there a way to 'normalize' it or or something?
EDIT:
here is a the jfiddle http://jsfiddle.net/EZktE/