当鼠标悬停在画布上的某些位置时,我正在尝试显示相应的工具提示.例如,当画布上的鼠标位置位于坐标(100,100)处时,显示工具提示1.当鼠标位置在(200,200)时,显示工具提示2等,
我已经添加了事件监听器来检测鼠标移动并获得鼠标位置.这是我的一部分:
window.addEventListener('mousemove',hover,false);
function getMousePos (canvas, event) {
var rect = canvas.getBoundingClientRect();
return {
x: event.clientX - rect.left,
y: event.clientY - rect.top
};
}
function hover (event){
pos = getMousePos(canvas,event);
if (condition to detect mouse hover)
//display tooltip_function (this is the function that I don't know how to implement)
}
Run Code Online (Sandbox Code Playgroud)