B
barry_normal
Hello there,
I'm not that familiar with Javascript so this hopefully is an easy
question to answer. Apologies if it's trivial but i haven't found a
simple solution elsewhere.
I have a <canvas> element on which I have drawn a number of lines
using the Line 'class' listed below.
The question is, can these lines accept event listeners? I'd like each
one to display a tool tip type message when they are moused over...
I don't seem able to get it working so any help would be greatly
appreciated.
All the best
BN
<code>
function Line(name, date, length){
// Get the canvas element.
var elem = document.getElementById(name);
if (!elem || !elem.getContext) {
return;
}
// Get the canvas 2d context.
var context = elem.getContext('2d');
if (!context) {
return;
}
context.strokeStyle = '#f6c540'; //
context.lineWidth = 2;
context.moveTo(date, 0);
context.lineTo(date, length);
context.stroke();
this.addEventListener("mouseover", handleMouse, true);
};
</code>
I'm not that familiar with Javascript so this hopefully is an easy
question to answer. Apologies if it's trivial but i haven't found a
simple solution elsewhere.
I have a <canvas> element on which I have drawn a number of lines
using the Line 'class' listed below.
The question is, can these lines accept event listeners? I'd like each
one to display a tool tip type message when they are moused over...
I don't seem able to get it working so any help would be greatly
appreciated.
All the best
BN
<code>
function Line(name, date, length){
// Get the canvas element.
var elem = document.getElementById(name);
if (!elem || !elem.getContext) {
return;
}
// Get the canvas 2d context.
var context = elem.getContext('2d');
if (!context) {
return;
}
context.strokeStyle = '#f6c540'; //
context.lineWidth = 2;
context.moveTo(date, 0);
context.lineTo(date, length);
context.stroke();
this.addEventListener("mouseover", handleMouse, true);
};
</code>