Nefarious1
Programmer
Hi -
I have recently been looking for some code that will allow me to monitor the mouse position for touch-screen devices. I found some code that worked, but am having problems parsing the example I found in to something more modular for my purposes. What I cant understand is why the second code example wont work ? I am guessing its something to do with scope, but any tips would be much appreciated.
===========================================================================================
CODE WORKS - BUT very "INLINE" I was trying to pull the code out in to distinct functions
===========================================================================================
================================================================================================
SIMILAR CODE _ BUT USING DISTINCT FUNCTIONS - THIS CODE DOES NOT WORK!
===============================================================================================
I dont think its due to the second attempt running outside of the "document Ready" function, but I am not sure. Anyway, any guidence would be much appreciated.
Cheers..
I have recently been looking for some code that will allow me to monitor the mouse position for touch-screen devices. I found some code that worked, but am having problems parsing the example I found in to something more modular for my purposes. What I cant understand is why the second code example wont work ? I am guessing its something to do with scope, but any tips would be much appreciated.
===========================================================================================
CODE WORKS - BUT very "INLINE" I was trying to pull the code out in to distinct functions
===========================================================================================
Code:
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div id="status">x, y</div>
<script>
$( document ).ready(
function()
{
document.addEventListener('touchmove', function(e) {
e.preventDefault();
$('#status').html('x='+event.touches[0].pageX + ' y= ' + event.touches[0].pageY);
}, false);
}
);
</script>
</body>
</html>
SIMILAR CODE _ BUT USING DISTINCT FUNCTIONS - THIS CODE DOES NOT WORK!
===============================================================================================
Code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div id="status">x, y</div>
<script>
document.addEventListener('mousemove', myFunction(e));
function myFunction(e)
{
e.preventDefault();
$('#status').html('x='+event.touches[0].pageX + ' y= ' + event.touches[0].pageY);
}
</script>
</body>
</html>
I dont think its due to the second attempt running outside of the "document Ready" function, but I am not sure. Anyway, any guidence would be much appreciated.
Cheers..