我知道这是非常基本的。我想将这个swipe-listener 包实现到我的 html 代码中。
这是自述文件中的示例代码:
const SwipeListener = require('swipe-listener');
var container = document.querySelector('#container');
var listener = SwipeListener(container);
container.addEventListener('swipe', function (e) {
var directions = e.detail.directions;
var x = e.detail.x;
var y = e.detail.y;
if (directions.left) {
console.log('Swiped left.');
}
if (directions.right) {
console.log('Swiped right.');
}
.
.
.
});
当我运行该文件时,出现“文档未定义”错误。我必须在这里指定什么?我假设我必须在“#container”中指定一个 div 元素。我有一个 iFrame,其中应该检测到滑动。这个 iFrame 有一个名称和 ID。我必须使用哪一种?
此外,我需要像这样的 index.html 中的文件。
<script>
require('./swipeListener.js')
</script>
这是正确的方法还是我必须放
<script type="text/javascript" src="swipeListener.js"></script>
?
阿波罗的战车
随时随地看视频慕课网APP
相关分类