Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
182
rated 0 times [  186] [ 4]  / answers: 1 / hits: 26801  / 10 Years ago, wed, june 18, 2014, 12:00:00
var direction = 
var mousemovemethod = function (e) {
var oldx = 0;
if (e.movementX < oldx) {
direction = left
} else if (e.movementX > oldx) {
direction = right
}
oldx = e.pageX;
}


This is how I detect the mouse direction and it works so good but it works only on Chrome, how I can make this compatible with other browsers (Firefox, Opera and at least ie8+ or ie9+).
No jQuery please.


More From » mouseevent

 Answers
5

Stick with pageX and define oldx in a higher scope, otherwise it's always zero



var direction = ,
oldx = 0,
mousemovemethod = function (e) {

if (e.pageX < oldx) {
direction = left
} else if (e.pageX > oldx) {
direction = right
}

oldx = e.pageX;

}


FIDDLE


[#70519] Monday, June 16, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradleymoisesy

Total Points: 121
Total Questions: 105
Total Answers: 95

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
bradleymoisesy questions
Wed, Dec 22, 21, 00:00, 2 Years ago
Tue, Jun 1, 21, 00:00, 3 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;