我想使用以下代码通过D3来获取鼠标位置:
var x = 0; svg.on('mousemove', function () { x = d3.mouse(this)[0]; });
但是x始终等于0。通过使用console.log(),我可以看到x的值在function()内部发生了变化,但在外部x恢复了初始值0。
x
0
console.log()
function()
我该如何保存x的值并在应用程序中稍后使用它?
用户名或电子邮箱地址
密码