作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用以下库通过我的 lit-element
实现手势:https://github.com/composi/gestures
在我的文件顶部,我有以下内容:
import { gestures } from '@composi/gestures'
gestures();
然后在我的渲染函数中我有:
render() {
return html`
<div class="tablet-menu " id="tablet-menu-T">
<div class="tablet-menu-body" on-swipe="${this._swipe}">
....
但是 _swipe
函数从未被调用,所以它似乎没有注册滑动命令。
我做错了什么?
最佳答案
这是使用了错误的事件处理程序语法。
<div class="tablet-menu-body" on-swipe="${this._swipe}">
使用 @
前缀代替 on-
前缀:
<div class="tablet-menu-body" @swipe="${this._swipe}">
参见:https://lit-html.polymer-project.org/guide/template-reference#event-listeners
注意:您不需要为 LitElement 类方法使用箭头函数。它们会自动使用正确的 this
引用进行调用。
关于javascript - @composi/gestures 滑动点亮元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64386118/
我正在尝试使用以下库通过我的 lit-element 实现手势:https://github.com/composi/gestures 在我的文件顶部,我有以下内容: import { gesture
我是一名优秀的程序员,十分优秀!