Note that there are some explanatory texts on larger screens.

plurals
  1. POHtml and java script that moves object with arrow keys?
    primarykey
    data
    text
    <p>Ok so I made a page that can move an image with the arrow keys but only the down and right functions work. I made the functions from a hide show script because i'm very new to javascript.</p> <p>Here is the code.</p> <p>left</p> <pre><code>function left(id) { var y = '5'; var z =document.getElementById(id).style.left; var x = parseInt(y)+parseInt(z); var state = document.getElementById(id).style.left; if (state == '1') { document.getElementById(id).style.left = x; } else { document.getElementById(id).style.left = x; } } </code></pre> <p>right</p> <pre><code>function right(id) { var y = '5'; var z =document.getElementById(id).style.right; var x = parseInt(y)+parseInt(z); var state = document.getElementById(id).style.right; if (state == '1') { document.getElementById(id).style.right = x; } else { document.getElementById(id).style.right = x; } } </code></pre> <p>up</p> <pre><code>function up(id) { var y = '5'; var z =document.getElementById(id).style.bottom; var x = parseInt(y)+parseInt(z); var state = document.getElementById(id).style.bottom; if (state == '1') { document.getElementById(id).style.bottom = x; } else { document.getElementById(id).style.bottom = x; } } </code></pre> <p>down</p> <pre><code>function down(id) { var y = '5'; var z =document.getElementById(id).style.top; var x = parseInt(y)+parseInt(z); var state = document.getElementById(id).style.top; if (state == '1') { document.getElementById(id).style.top = x; } else { document.getElementById(id).style.top = x; } } </code></pre> <p>then the arrow key script</p> <pre><code>document.onkeyup = KeyCheck; function KeyCheck() { var KeyID = event.keyCode; switch(KeyID) { case 37: right('img'); break; case 38: up('img') break case 39: left('img'); break; case 40: down('img'); break; } } </code></pre> <p>and then the html</p> <pre><code>&lt;img id="img" src="http://trevorrudolph.com/logo.png" style="position:absolute; left:1; bottom:1; right:1; top:1;"&gt; </code></pre> <p>you can download the html at <a href="http://trevorrudolph.com/arrow.zip" rel="nofollow">arrow.zip</a></p> <p>the actual page is <a href="http://trevorrudolph.com/arrow.html" rel="nofollow">here</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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