I found this solution in another thread. It works correctly when moving the mouse down.
However, if you move the mouse up with a slight curve in it, the console will register From Topand From Bottom.
$(document).ready(function() {
var mY = 0;
$(document).mousemove(function(e) {
if (e.pageY < mY) {
console.log('From Bottom');
} else {
console.log('From Top');
}
mY = e.pageY;
});
});
code {
background: #ededed;
padding: 0 5px;
}
span {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
So instead of moving <span>straight up</span>, go from the <span>left bottom corner</span> to the <span>right top corner</span> with a small <span>curve</span>. Moving your mouse up or down. It will log both <code>From Top</code> and <code>From Bottom</code>
Run codeHide resultHow can I accurately measure whether the mouse moves up or down?
source
share