If you want the circle to be positionned EXACTLY were the user clicks...
You have to know that pageX
and pageY
doesn't give you the position of the "tip" of the mouse arrow... But the center of the mouse icon displayed.
So, ""usual icons" dimentions are 20px x 20px.
I have updated your Plunker.
I have added a "dot" to show the exact position where a user expects it to be the center, which is the tip of the arrow.
I made the circle much bigger to be sure about the middle.
See by yourself on this forked and updated Plunker.
Code is:
$(function(){
$('#fx').click(function(e){
var width = 300; // Width of the element has to be hard coded here;
var radius = width/2;
console.log(radius); // Since element is a circle, the radius is enought to set position.
var mouseTip = 10; // But mouse arrow tip has to be taken in account.
var circle=$('<div class="circle"></div>');
circle.css('top',e.pageY-radius-mouseTip);
circle.css('left',e.pageX-radius-mouseTip);
$('#fx').append(circle);
var dot=$('<div class="dot"></div>'); // This is only intended to show where user REALLY wants to clic
// and the FACT that there is a correction to apply.
dot.css('top',e.pageY-mouseTip);
dot.css('left',e.pageX-mouseTip);
$('#fx').append(dot);
});
});
So this is great for the "arrow" default cursor, it will need another mouse correction value if you use the "pointer" icon.