Take a look at the updated script .
A quick fix removes the positioning of the canvas:
#canvasDiv { width: 30%; height: 400px; cursor:crosshair; background-color:
The problem is the positioning of the template. Since absolute is still "relative".
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 #template position will consider the position of #canvasDiv unless you leave #canvasDiv with the default static position.
More on positioning on w3schools
Positioning absolutely elements inside relatively positioned elements: here
A great example of your problem is tabs 3 and 4.
If you want to adhere to the relative positioning of the canvasDiv , you need to update the script, so it takes into account the location of the canvasDiv :
var x = event.pageX; var y = event.pageY; var canvasPos = $(this).offset();
Look fiddle
source share