I'm attempting to implement functionality where a canvas with a linear gradient can be clicked, capturing the image data at that specific point.
Additionally, I aim to position a yellow picker relative to the click point on the canvas.
Issue 1: Clicking on the lower part (white area) results in incorrect color value retrieval.
Issue 2: The yellow picker is not aligning perfectly with the click point.
Note: The canvas appears round due to the border-radius setting of 50%.
The crucial code snippet provided in the above fiddle link is:
$(wheel_canvas).click(function(e)
{
dragging = false;
x = e.pageX;
y = e.pageY;
can_p = $('#wheel_canvas').offset();
x = x - $(document).scrollLeft() - can_p.left;
x = y - $(document).scrollTop() - can_p.top;
$('#wheel_picker').css({'left':x+'px','top':y+'px'});
var data=wheel_context.getImageData(x,y,1,1).data;
pixelData = data;
rgbString = 'rgb('+pixelData[0]+', '+pixelData[1]+', '+pixelData[2]+')';
hex = rgb2hex(rgbString);
$('#color').val(hex);
$('#color').css('background',hex);
$('#feedback').html("Coordinates : "+x+","+y+" Color: "+hex);
});
Edit: Providing an answer with the inclusion of a JS Fiddle would enhance clarity and understanding :)