I know this is very basic. I want to implement this swipe-listener package into my html code.
This is the example code from the readme:
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.');
}
.
.
.
});
When I run the file, I get a "document is not defined" error. What do I have to specify here? I was assuming that I have to specify a div element in "#container". I have an iFrame in which the swipe should be detected. This iFrame has a name and id. Which one must I use?
Furthermore I required the file in the index.html like this.
<script>
require('./swipeListener.js')
</script>
Is this the right way or do I have to put
<script type="text/javascript" src="swipeListener.js"></script>
?