0

Dont working pagex

what dont working pagex

14th Dec 2017, 7:07 AM
Igor Mamedov
Igor Mamedov - avatar
5 Answers
+ 1
Here's an example: <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p id="i"></p> <script> // This gets the X position of the mouse pointer while moving the mouse pointer over the window body. window.onmousemove = function(event) { document.getElementById("i").innerHTML = event.pageX; }; // This get the X position of the first touchpoint. (mobile touchscreen) while moving the touch over the window body. window.ontouchmove = function(e) { // here I shortened the event identifier name to 'e' instead document.getElementById("i").innerHTML = e.touches[0].pageX; // you could also use clientX here. } </script> </body> </html>
14th Dec 2017, 8:14 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
You should post your code. I'm going to guess that you are referring to the only public code you have. The issue with this code is that you have a script tag outside of your body tag. Place the entire script tag and its contents just before the closing body tag and your code should work. Also, you can check the gutter to the left of the editor and see that there is an error icon(red x) there. Hover your mouse pointer over the error icon to read the error message.
14th Dec 2017, 7:15 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Ok, so first input is a self contained tag. There is no closing tag. So <input type="text" value="0" id="i"></input> would be: <input type="text" value="0" id="i"> But you don't really need an input here from what I can tell. Second: document.getElementById("i").value=event.PageX; doesn't make sense, because there is no event that has been triggered and passed, nor has the identifier/variable 'event' been declared. Also, PageX is incorrect you would need to use pageX. See below for more information. https://www.w3schools.com/jsref/event_pagex.asp https://www.w3schools.com/jquery/event_pagex.asp
14th Dec 2017, 7:52 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
I edited my previous code example, just in case you are expecting a result from the playground on a mobile touchscreen device. Note that in order to get the event you need to capture it via an event listener that belongs to a particular object in the pages DOM (Document Object Model). In the example I'm listening for the mousemove and touchmove events that belong to the browsers window object. An event listener will always have the event passed in as an argument. You can name it whatever you wish. See in one I name it event and the other it is shortened to just e. You then use this identifier within the event listeners function to access the event that was passed in. Hope that helps.
14th Dec 2017, 8:21 AM
ChaoticDawg
ChaoticDawg - avatar
0
Not working: <body> <input type="text" value="0" id="i"></input> <script> document.getElementById("i").value=event.PageX; </script> </body>
14th Dec 2017, 7:29 AM
Igor Mamedov
Igor Mamedov - avatar