从箭头函数中检索值(popmotion 的指针 X 位置)
Retrieve value from an arrow function (popmotion's pointer X position)
我需要将指针 X 位置存储在一个变量中。
根据 popmotion 文档 (See link here),以下内容可以解决问题:
import { pointer } from 'popmotion';
pointer().start(({ x }) => console.log(x));
事实上,通过使用上面的代码,x 的确切值会显示在控制台中,但我在使用我的代码中的值时遇到了麻烦。
我已经试过了:
const X = pointer().start(({ x }) => x);
const X = pointer().start(({ x }) => { return x; });
但 console.log(X) returns {停止: ƒ}
我对箭头函数不是很熟悉,非常感谢任何帮助,谢谢
let x;
pointer.start(it => x = it.x);
请注意,在 start
回调之前,x
将是未定义的。
我需要将指针 X 位置存储在一个变量中。 根据 popmotion 文档 (See link here),以下内容可以解决问题:
import { pointer } from 'popmotion';
pointer().start(({ x }) => console.log(x));
事实上,通过使用上面的代码,x 的确切值会显示在控制台中,但我在使用我的代码中的值时遇到了麻烦。
我已经试过了:
const X = pointer().start(({ x }) => x);
const X = pointer().start(({ x }) => { return x; });
但 console.log(X) returns {停止: ƒ}
我对箭头函数不是很熟悉,非常感谢任何帮助,谢谢
let x;
pointer.start(it => x = it.x);
请注意,在 start
回调之前,x
将是未定义的。