snipt

Ctrl+h for KB shortcuts

JavaScript

Show mouse position

1
2
3
4
5
document.onmousemove = function(e){
var x = e.pageX;
var y = e.pageY;
e.target.title = "X is "+x+" and Y is "+y;
};
https://snipt.net/embed/3fab55f3265b101be9d17e61bfc020be/
https://snipt.net/raw/3fab55f3265b101be9d17e61bfc020be/
3fab55f3265b101be9d17e61bfc020be
js
JavaScript
5
2016-09-22T00:48:08
True
False
False
Mar 20, 2014 at 05:41 AM
/api/public/snipt/123302/
show-mouse-position
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nb">document</span><span class="p">.</span><span class="nx">onmousemove</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span> </span><span id="L-2"><a name="L-2"></a><span class="kd">var</span> <span class="nx">x</span> <span class="o">=</span> <span class="nx">e</span><span class="p">.</span><span class="nx">pageX</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="kd">var</span> <span class="nx">y</span> <span class="o">=</span> <span class="nx">e</span><span class="p">.</span><span class="nx">pageY</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="nx">e</span><span class="p">.</span><span class="nx">target</span><span class="p">.</span><span class="nx">title</span> <span class="o">=</span> <span class="s2">&quot;X is &quot;</span><span class="o">+</span><span class="nx">x</span><span class="o">+</span><span class="s2">&quot; and Y is &quot;</span><span class="o">+</span><span class="nx">y</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">};</span> </span></pre></div> </td></tr></table>
absolute, coordinates, mouse, position
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.