PDA

View Full Version : Can't move span...


primadog
07-17-2002, 05:50 PM
I am trying to move a span with the pixelX and pixelY style using window.event.KeyCode for l, r, u, d

but for some reason the code won't work

<html>
<head>
<script SRC="source.js">

</script>
</head>
<BODY onkeypress="typeMe()">
<SPAN id=youCha style="position:absolute; left:100; top:200; width:300"><img src="archerA1.bmp"></SPAN>
<span id=Dra style="position:absolute; right:100; top:80; width:300"><img src="dragon.bmp"></span>
<span id=nameField style="position:absolute; left=50; top=400; width:300"></span>
</body>
</html>

----------------------


var input;


function typeMe() {
input = window.event.keyCode;
nameField.innerText = nameField.innerText + String.fromCharCode(window.event.keyCode);
if (input = 108)
youCha.style.pixelLeft -= 50;

if (input = 114)
youCha.style.pixelLeft += 50;


if (input = 106)
youCha.style.pixelTop -= 50;


if (input = 98)
youCha.style.pixelTop += 50;
}



can someone help me out?:confused:


Also, i need to know where can i dl a free software that allows me to turn bmp files to gif and animated gif files... (with transparent fuction)

tamienne
07-17-2002, 06:00 PM
I don't think you can use SPAN. If you change it to DIV it'll work.

Sorry, can't help you on the image software.

Roy Sinclair
07-17-2002, 06:33 PM
SPAN is positionable, the problem is syntax

All of the IF conditions have a single = sign when they should be == to test for equality. Right now the code performs an assignment and all four conditions are executed in turn.

primadog
07-18-2002, 01:55 AM
oh :D that's the bug...

primadog
07-18-2002, 02:02 AM
One more thing. how do i make it so it move left when the user type 'left' and etc.

Algorithm
07-18-2002, 03:15 AM
The directional keys won't throw a keypress event, so you need to change the onkeypress to onkeydown. I can't remember their keycode offhand, but you could test for it by putting this line in your function:

alert(input);

primadog
07-18-2002, 06:16 AM
how do i modify the inside of a <textarea></textarea>

also, waz the difference between span and div?

jkd
07-18-2002, 06:23 AM
Originally posted by primadog
also, waz the difference between span and div?

<span> is an inline element - doesn't cause line breaks.

<div> is a block element - causes line breaks.