Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing mouse coordinates as pixel values for javascript functions
    text
    copied!<p>Is there any way to input mouse click coordinates as the amount by which to change an element property as in the following sort of function? Specifically is there a way to use the Y coordinate of the mouse click as the pixel amount for the height instead of a fixed pixel number?</p> <pre><code>function changeObject() { document.getElementById('object').style.height = '500px'; } </code></pre> <p>Edit:</p> <p>Use cookies to remember former height</p> <pre><code>&lt;script type="text/javascript"&gt; function setCookie (name, value, expires, path, domain, secure) { document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } function getCookie (name) { var cookie = " " + document.cookie; var search = " " + name + "="; var setStr = null; var offset = 0; var end = 0; if (cookie.length &gt; 0) { offset = cookie.indexOf(search); if (offset != -1) { offset += search.length; end = cookie.indexOf(";", offset); if (end == -1) { end = cookie.length; } setStr = unescape(cookie.substring(offset, end)); } } if (setStr == 'false') { setStr = false; } if (setStr == 'true') { setStr = true; } if (setStr == 'null') { setStr = null; } return(setStr); } document.getElementById('bookmarktag').onclick = function(event){ var clickX = event.clientX + document.body.scrollLeft; var clickY = event.clientY + document.body.scrollTop; document.getElementById('bookmark').style.height = clickY + 'px'; document.getElementById('bookmark2').style.marginTop = clickY + 'px'; document.getElementById('bookmarkdiv2').style.display = 'block'; document.getElementById('bookmarkdiv').style.display = 'none'; setCookie('bookmark_state', true); } function checkBookmark() { if (getCookie('bookmark_state') == null) { document.getElementById('bookmarkdiv').style.display = 'block'; } if (getCookie('bookmark_state') == true) { document.getElementById('bookmark').style.height = clickY + 'px'; document.getElementById('bookmark2').style.marginTop = clickY + 'px'; document.getElementById('bookmarkdiv2').style.display = 'block'; document.getElementById('bookmarkdiv').style.display = 'none'; } } &lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload