gpt4 book ai didi

dart - 无法从mousemove事件获取鼠标指针信息

转载 作者:行者123 更新时间:2023-12-03 03:02:15 27 4
gpt4 key购买 nike

在普通的JS Polymer中,我可以执行类似this的操作:

<dom-module id="my-module">
<template>
<div on-mousemove="mousemove">Text here!</div>
</template>
<script>
Polymer({
is: 'my-module',

mousemove: function (event) {
console.log(event);
}
});
</script>
</dom-module>
这将打印一个包含鼠标指针坐标的鼠标移动事件。
但是,请考虑以下Dart项目:
pubspec.yaml
name: example
description: "stuff here"
version: 0.1.0
dependencies:
polymer: ^1.0.0-rc.18
web_components: ^0.12.0
browser: ^0.10.0
transformers:
- polymer:
entry_points:
- web/index.html
网站/index.dart
library photon.index;

import 'package:example/test.dart';

export 'package:polymer/init.dart';
import 'package:polymer/polymer.dart';
web / index.html
<head>
<script src="packages/web_components/webcomponents-lite.min.js"></script>
<script src="packages/web_components/dart_support.js"></script>
</head>
<body unresolved>
<my-module></my-module>

<script type="application/dart" src="index.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
lib / test.dart
@HtmlImport('test.html')
library example.test;

import 'package:polymer/polymer.dart';
import 'package:web_components/web_components.dart' show HtmlImport;

@PolymerRegister('my-module')
class MyModule extends PolymerElement {
MyModule.created() : super.created();

@reflectable
void mousemove(event, [_]) {
print(event);
}
}
lib / test.html
<dom-module id="my-module">
<template>
<div on-mousemove="mousemove" id="target">Text here!</div>
</template>
</dom-module>
这大致相当于JavaScript版本。但是,它将改为打印 CustomEventWrapper的实例,该实例缺少有关光标所在位置的信息。有什么方法可以访问鼠标指针信息?

最佳答案

这应该工作

  @reflectable
void mousemove(CustomEventWrapper event, [_]) {
MouseEvent mouseEvent = event.original;
print('x: ${mouseEvent.client.x}');
print('y: ${mouseEvent.client.y}');
}

关于dart - 无法从mousemove事件获取鼠标指针信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39628617/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com