I just wanted to get the mouse position using D3 by using the following code:
var x = 0;
svg.on('mousemove', function () {
x = d3.mouse(this)[0];
});
but x
is always equal to 0
. By using console.log()
, I can see that x
value is getting changed just inside the function()
but out of it x
got its initial value of 0
.
How can I save the x
value and use it later in my application?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…