Js Pagex And Pagey Take The Coordinate Plus The Margin Of Relative Position Div?
Solution 1:
Take a look at the updated fiddle.
Quick solution remove positioning of canvas:
#canvasDiv { 
    width: 30%;
    height: 400px;  
    cursor:crosshair;  
    background-color: #458B00; 
    /* position: relative; */  
    ...
}
The problem is with the positioning of template. Because absolute is still "relative".
The definition of absolute positioning: An absolute position element is positioned relative to the first parent element that has a position other than static.
Therefore the position of #template will take into consideration the position of #canvasDiv unless you leave #canvasDiv with the default static positioning.
Learn more about positioning at w3schools
Positioning absolutely elements inside relatively positioned elements: here
Great example of your problem tabs 3 & 4.
Should you wish to stick with the relative positioning of canvasDiv, you have to update the script, so it takes into account the positioning of canvasDiv:
var x = event.pageX;  
var y = event.pageY;   
var canvasPos = $(this).offset(); // in the context of your script this refers to #canvasDivvar styles = {
   "left" : x - canvasPos.left, // remove its left offset"top" : y - canvasPos.top // remove its top offset
};
Check out the fiddle
![Array Slice Returning [object Object] Instead Of Value](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEZR1HtNb7Cu-zFkWj8JhcNIalqp5JuTCYC04mfY9PnrEAiY6hwfgJmH0aOmBhUm4JJDR_oj_8TY8PTKMiPPS1YbcZJBqYYqP0fxcExVfJ4ROdgVGPrvVGNQIQRCXgdy2asyrxtLmRb40/w192-h108-n-k-rw-no-nu/nomage+%25281%2529.png)
Post a Comment for "Js Pagex And Pagey Take The Coordinate Plus The Margin Of Relative Position Div?"