05-09-2018 05:35
05-09-2018 05:35
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.
05-12-2018 12:58
05-12-2018 12:58
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
05-11-2018 14:12 - edited 05-11-2018 14:16
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
05-11-2018 14:17 - edited 05-15-2018 07:15
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
05-11-2018 14:17 - edited 05-11-2018 14:19
05-11-2018 14:17 - edited 05-11-2018 14:19
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
05-11-2018 14:22
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
05-11-2018 14:27
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
05-12-2018 11:05
did you manage to get the swipes to work? if so could you share how you did this?
05-12-2018 12:57
05-12-2018 12:57
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
05-12-2018 12:58
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
05-12-2018 14:52
Thanks for the responses I'm going to give a shot tonight.
05-13-2018 17:17
05-13-2018 17:17
@Pietero the onmousedown / onmouseup worked great.
Thanks