05-09-2018 05:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-09-2018 05:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Is there as why to bind or detect when the user has swiped left or right on the screen in JavaScript?
I have searched for the documentation it's either not in there or I totally missed it.
I did look at the panorama component and it's not going to work for what I need.
Answered! Go to the Best Answer.

Accepted Solutions
05-12-2018 12:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-12-2018 12:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
What i use in My app is pretty simple but it works
var y = 0;
var x=0;
var timerText = document.getElementById("timer");
timerText.onmousedown = function(evt) {
y = evt.screenY;
x = evt.screenX;
}
timerText.onmouseup = function(evt) {
let yMove = evt.screenY-y;
let xMove = evt.screenX-x;
if (yMove< -60) {//swipe up };
if (yMove> 60) {//swipe down};
if (xMove< -60) {//swipe left };
if (xMove> 60) {//swipe right};
}
05-11-2018 14:12 - edited 05-11-2018 14:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-11-2018 14:12 - edited 05-11-2018 14:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You don't have an event for swipe, but I think you can read the x position for mouse down and x position for mouse up and 'guess' the swipe direction. I would do something like
let myButton = document.getElementById("myButton"); myButton.onmousedown = function(evt) { console.log("Before swipe x position: " + evt.screenX); }
myButton.onmouseup = function(evt) { console.log("After swipe x position: " + evt.screenX); }

05-11-2018 14:17 - edited 05-15-2018 07:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-11-2018 14:17 - edited 05-15-2018 07:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

05-11-2018 14:17 - edited 05-11-2018 14:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-11-2018 14:17 - edited 05-11-2018 14:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You don't have an event for swipe, but I think you can read the x position for mouse down and x position for mouse up and 'guess' the swipe direction.
I would do something like :
let myButton = document.getElementById("myButton"); myButton.onmousedown = function(evt) { console.log("Before swipe x position: " + evt.screenX); } myButton.onmouseup = function(evt) { console.log("After swipe x position: " + evt.screenX); }

05-11-2018 14:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-11-2018 14:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I would do something like this trying to simulate a swipe event.
Compare the initial position of the x and the latest x position to know what way is the user swiping
let myButton = document.getElementById("myButton"); myButton.onmousedown = function(evt) { console.log("Before swipe x position: " + evt.screenX); } myButton.onmouseup = function(evt) { console.log("After swipe x position: " + evt.screenX); }

05-11-2018 14:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-11-2018 14:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I would try something like this to simulate the swipe:
let myButton = document.getElementById("myButton"); myButton.onmousedown = function(evt) { console.log("Mouse moved: " + evt.screenX); }
myButton.onmouseup = function(evt) { console.log("Mouse moved: " + evt.screenX); }
Try to compare the x before the move and after the move to get the direction.

05-12-2018 11:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-12-2018 11:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
did you manage to get the swipes to work? if so could you share how you did this?

05-12-2018 12:57
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-12-2018 12:57
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi, I would try something like this to simulate the swipe movement:
var myButton = document.getElementById("myButton"); myButton.onmousedown = function(evt) { console.log("Mouse moved: " + evt.screenX); }
myButton.onmouseup = function(evt) { console.log("Mouse moved: " + evt.screenX); }
And compare the results to see what direction the user swiped.

05-12-2018 12:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-12-2018 12:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
What i use in My app is pretty simple but it works
var y = 0;
var x=0;
var timerText = document.getElementById("timer");
timerText.onmousedown = function(evt) {
y = evt.screenY;
x = evt.screenX;
}
timerText.onmouseup = function(evt) {
let yMove = evt.screenY-y;
let xMove = evt.screenX-x;
if (yMove< -60) {//swipe up };
if (yMove> 60) {//swipe down};
if (xMove< -60) {//swipe left };
if (xMove> 60) {//swipe right};
}
05-12-2018 14:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-12-2018 14:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks for the responses I'm going to give a shot tonight.

05-13-2018 17:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-13-2018 17:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Pietero the onmousedown / onmouseup worked great.
Thanks

