What is the role of screenX Mouse Event in JavaScript?

HTMLJavascriptProgramming Scripts

<p>When an event is triggerd, the screenX mouse event returns the horizontal coordinate of the mouse pointer.</p><h2>Example</h2><p>You can try to run the following code to learn how to implement <em>screenX</em><em>&nbsp;</em>Mouse event in JavaScript.</p><pre class="prettyprint notranslate">&lt;!DOCTYPE html&gt; &lt;html&gt; &nbsp; &nbsp;&lt;body&gt; &nbsp; &nbsp; &nbsp; &lt;p onclick = &quot;coordsFunc(event)&quot;&gt;Click here to get the x (horizontal) and y (vertical) coordinates of the mouse pointer.&lt;/p&gt; &nbsp; &nbsp; &nbsp; &lt;script&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;function coordsFunc(event) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var x_coord = event.screenX; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var y_coord = event.screenY; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var xycoords = &quot;X coords= &quot; + x_coord + &quot;, Y coords= &quot; + y_coord; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write(xycoords); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &lt;/script&gt; &nbsp; &nbsp;&lt;/body&gt; &lt;/html&gt;</pre>
raja
Updated on 23-May-2020 09:36:05

Advertisements