Hello I have a pretty basic question about events in JS.
Can I do something like:
var myobj = { };
document.getElementById("myid").onmousemove = function (e) {
myobj.e = e;
}
...
// called from function which will occure after onmousemove guaranteed
document.getElementById("info").innerHTML = myobj.e.type;
I need this for my game. I want to save event data and dispatch it later in update function of my game loop.
Okay. Here is jsfiddle.
<p id="info"></p><canvas id="can" width="400px" height="400px" style="border: 2px solid red"></canvas>
var my = { };
document.getElementById("can").onclick = function(e, custom) {
my.e = e;
}
document.getElementById("can").onmouseover = function(e, custom) {
my.e = e;
}
document.getElementById("can").onmouseout = function(e, custom) {
my.e = e;
}
document.getElementById("can").oncontextmenu = function(e, custom) {
my.e = e;
}
document.getElementById("info").innerHTML = my.e.type;
And it doesnt work.
Yes, you could do something like this
DEMO